Get server time php and javascript
<p>I have this script 
1- It gets the time of number of messages sent (time identified by client)
2- Compare it to now time (server time)
3- change the background of each message according to the time difference
Now i have a problem in updating the clock, i update it each second (ajax request) but i think it is making the system heavier. Is there a way i can update the clock (server time) every minute?
This is the script:
javascript:
function to get server time</p>

<pre><code>  function gettime()
  {
    $.post('gettimeofday.php',
         function(t){
         document.getElementById('formatted_time').value = t;
   });
     setTimeout("gettime()",1000);
  }
</code></pre>

<p>php:</p>

<pre><code>$server_current_time = time();
echo(date("H:i",$server_current_time));
</code></pre>

<p>javascript:
function to calculate the time difference:</p>

<pre><code>function checkTime(Time_to_send)
{
  var time_from_db = Time_to_send.split(":",2);
  var time_hours = Number(time_from_db[0] * 60 );
  var time_min = Number(time_from_db[1]);
  var time_of_msg = time_hours + time_min;
  var current_time = document.getElementById('formatted_time').value;
  var ct = current_time.split(":",10); 
  var now_hours = Number(ct[0] * 60);
  var now_min = Number(ct[1]);
  var time_live = now_hours + now_min;
  var time_diff = time_of_msg - time_live;
  return (time_diff);
}
</code></pre>

<p>And after that i check the time difference and change the background color.
I hope you can help me find a solution and if you have any question concerning my question please tell me.</p>
