php - UTC clock based on server time? -


i have javascript clock gets time in utc, works, time based off client's computer. base time off of server instead? using php server scripting language. not use ajax.

<?php $year   = date("y"); $month  = date("m"); $day    = date("d"); $hour   = date("h"); $minute = date("i"); $str    = $year . $month . $day . $hour . $minute; echo "history.pushstate('', 'title', '?q=$str');"; echo "var ct = '$str';"; ?> function dt(){     var d = new date();     d = new date(d.getutcfullyear(), d.getutcmonth(), d.getutcdate(), d.getutchours(), d.getutcminutes(), d.getutcseconds());     d.settime(d.gettime());     v = d.getfullyear() + "" +             padstr(d.getmonth()) + "" +             padstr(d.getdate()) + "" +             padstr(d.gethours()) + "" +             padstr(d.getminutes()) + "" + padstr(d.getseconds());     if(ct !== v){         history.pushstate('', 'title', '?q=' + v);         ct = v;     }     settimeout('dt()', 1000); } dt(); 

edit

    var = moment().format("<?php echo date("y-m-d h:i:s", time()); ?>");     document.getelementbyid("time").innerhtml = a;     function clock_tick(){         var time = moment(a);         time.add('second', 1);         = time.format("yyyy-mm-dd hh:mm:ss");         document.getelementbyid("time").innerhtml = a;         settimeout("clock_tick()", 1000);     }     clock_tick(); 

this should started. don't need use moment.js, wanted try out since suggested it.

 <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script src="moment.js"></script> <script language="javascript"> $(function() {     $('#clock')[0].innerhtml = moment().format("<?php echo date("y-m-d h:i:s", time()); ?>");     clock_tick(); }); function clock_tick(){     var clock_div = $('#clock')[0];     var time = moment(clock_div.innerhtml);     time.add('second', 1);     clock_div.innerhtml = time.format("yyyy-mm-dd hh:mm:ss");     settimeout("clock_tick()", 1000); } </script> </head> <body> <div id="clock"></div> </body> </html> 

then stated earlier may need set:

date_default_timezone_set("utc");

reference link:
http://php.net/manual/en/function.date.php


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -