Let's use the @DemoS example
The server must have a script sent by the server time:
time.php:
<?php $servTime=Array(); //$this_time=time(); $servTime['currentYear']=date("Y"); $servTime['currentMonth']=date("n"); $servTime['currentDate']=date("j"); $servTime['currentDay']=date("N"); $servTime['currentHours']=date("G"); $servTime['currentMinutes']=date("i"); $servTime['currentSeconds']=date("s"); echo encode_json($servTime); ?>
Next, we use the @DemoS functions to be redesigned so that they do not contact the server every second, but adding 1 to seconds will generate minutes and hours (here you will have to think out).
$(document).ready(function(){ var objTime; $.getJSON("time.php", function(data){ objTime=$.parseJSON(data); }); });
objTime will be a time object. objTime.currentYear - will correspond to the year and so on.
Next we pass the objTime object to the clock () function;