datetime - JavaScript clock based on TimeAPI -


i want create javascript clock based on timeapi.org. reason want make sure client-side has exact same time server.

in svclock(json) saves year/month/day/hour/...etc in vars when i'm trying put vars in sethours in clock fucnction clock's format becomes this:
1391670641381:1391670761381:1391670727381 instead of 15:27:06.

is there easier way this?

<html> <head>   <script> var svtime,svyear,svmonth,svdate,svday,svhour,svmin,svsec,newtime;  function svclock(json) {     svtime=new date(json.datestring);     svyear=string(svtime).substr(11,4);     svmonth=string(svtime).substr(4,3);     svdate=string(svtime).substr(8,2);     svday=string(svtime).substr(0,3);     svhour=string(svtime).substr(16,2);     svmin=string(svtime).substr(19,2);     svsec=string(svtime).substr(22,2);     newtime=svhour+':'+svmin+':'+svsec;     //newtime=svyear+'/'+svmonth+'/'+svdate+'('+svday+')'+' '+svhour+':'+svmin+':'+svsec; }  function starttime() {     var today=new date();     var h=today.sethours(svhour);     var m=today.setminutes(svmin);     var s=today.setseconds(svsec);      document.getelementbyid('clock').innerhtml=h+":"+m+":"+s;     t=settimeout(function(){starttime()},1000); } </script>   <script type="text/javascript" src="http://timeapi.org/gmt/now.json?callback=svclock"></script>   </head>  <body onload="starttime()"> <div id="clock"></div> </body> </html> 


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -