function clock() { document.write(''); // here's the PHP code that spawn out the server local time // // now we represent the server time as javascript date var server = new Date(2017, 12, 17, 8, 49, 46).getTime(); // var server = new Date(2017, 12, 17, 8, 49, 46).getTime(); // var server = new Date(2000, 2, 1, 1, 1, 1).getTime(); // calculate the client time var client = new Date().getTime(); // run our ticker tick(client-server); } function tick(diff) { var d = new Date(new Date().getTime()-diff); var i = d.getMinutes(); if(i < 10) i='0'+i; var s = d.getSeconds(); if(s < 10) s='0'+s; var clock = document.getElementById("clock"); if(clock) { clock.innerHTML= d.getHours()+':'+i+':'+s+' am'; setTimeout('tick(' + diff + ');', 1000); } }