Get the server time in PHP and have it written in to a time reference in a JavaScript.
I also see that you are using a method of gathering time data that is really out of the ark.
Write in the current server time with PHP
<?php
date_default_timezone_set('America/Los_Angeles');
$rfc = date("r");
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>The Server Time</title>
<script>
timeSrv = new Date( "<?php echo $rfc;?>" ).getTime();
...
...
stringTime = new Date(timeSrv ).toUTCString().slice(17,25); // returns 00:00:00 format time
...
...
</script>
</head>
You will need to sub the local timezone of your server here date_default_timezone_set('America/Los_Angeles');
What you then have is a date object returned by the server, set on the clients machine as milliseconds
the stringTime will be a string time representation already formatted
You will need to have other time functions if you want to have the time of this object advanced, because this is in milliseconds, you can incorporate other functions that return milliseconds so you can calculate what you need.
The JavaScript Date() object understands many different time formats, string dates such as RFC dats and ISO dates and times, milliseconds and d/m/y h
s formats.
Avoid using setTimeout callbacks, they take time to set up and consume time, use the setInterval, it only needs to be set once and it will keep on calling the function until page is shut down or navigated away from.