Copy this code to a file, name it "servertime.php" and upload to your server:
Code: Select all
<?php
?>
<__script__ type="text/javascript">
<!--
function clock() {
document.write('<span id="clock"></span>');
// here's the PHP code that spawn out the server local time
<?php list($sy,$sm,$sd,$sa,$sh,$si,$ss) = explode(",", date("Y,n,j,a,g,i,s")); ?>
// now we represent the server time as javascript date
var server = new Date(<?=$sy?>, <?=$sm?>, <?=$sd?>, <?=$sh?>, <?=intval($si)?>, <?=intval($ss)?>).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='Current Server Time: '+
d.getHours()+':'+i+':'+s+' <?=$sa?>';
setTimeout('tick(' + diff + ');', 1000);
}
}
//-->
</__script>
Within the HEAD section of your template add:
Code: Select all
{php} require_once('servertime.php'); {/php}
Place this code where you want the clock to show - I put mine in the footer:
Code: Select all
{literal}<__script__ type="text/javascript">clock();</__script>{/literal}