JavaScript clock based on TimeAPI

I want to create a JavaScript clock based on
The reason is I want to make sure the client-side has the exact the same time as the server.

In svclock(json) it saves year/month/day/hour/…etc in vars
but when I’m trying to put those vars in setHours in my clock fucnction
the clock’s format becomes like this:
instead of 15:27:06.

  • Javascript show milliseconds as days:hours:mins without seconds
  • Convert times created by Javascript's getTime() method to ruby Time objects
  • Detecting changes to system time in JavaScript
  • JavaScript won't parse GMT Date/Time Format
  • Convert Microsoft JSON Date to Local DateTime Using Moment JS Only
  • new Date() set to 31 december 2014 says 1st december instead
  • Is there an easier way to do this?

    var svtime,svyear,svmonth,svdate,svday,svhour,svmin,svsec,newtime;
    function svclock(json) {
        svtime=new Date(json.dateString);
        //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);
    <script type="text/javascript" src=""></script>
    <body onload="startTime()">
    <div id="clock"></div>

  • How to convert date in RFC 3339 to the javascript date object(milliseconds since 1970)
  • What is the Best Practice for Encoding Dates in JSON?
  • Convert time interval given in seconds into more human readable form
  • Convert PHP date into javascript date format
  • Javascript, Time and Date: Getting the current minute, hour, day, week, month, year of a given millisecond time
  • Calculating year, month, days between dates in google apps script