I've seen this covered in other forums but for what ever reason I can't get it to work for me. Perhaps many of you have done this before and would be willing to advise?
I need to create a clock on a web page that starts with the calling server time. That means calling the js function with a parameter when constructing the web page.
My code looks something like this:
$SysTime = time();
print <<<EOD
<script>
function clock () {
var serverdate = new Date(" . $SysTime . "000");
}
function padlength(what) {
var output=(what.toString().length==1)? "0"+what : what
return output
}
function displaytime() {
serverdate.setSeconds(serverdate.getSeconds()+1)
var datestring = montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate())+", "+serverdate.getFullYear()
var timestring = padlength(serverdate.getHours()) + ":" + padlength(serverdate.getMinutes()) + ":" + padlength(serverdate.getSeconds())
document.getElementById("_clock").innerHTML = datestring+" " + timestring
}
</script>
EOD;
If I don't try to set the initial value of the date object it seems to work. But when I do it simply does nothing.
Thanks
I need to create a clock on a web page that starts with the calling server time. That means calling the js function with a parameter when constructing the web page.
My code looks something like this:
$SysTime = time();
print <<<EOD
<script>
function clock () {
var serverdate = new Date(" . $SysTime . "000");
}
function padlength(what) {
var output=(what.toString().length==1)? "0"+what : what
return output
}
function displaytime() {
serverdate.setSeconds(serverdate.getSeconds()+1)
var datestring = montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate())+", "+serverdate.getFullYear()
var timestring = padlength(serverdate.getHours()) + ":" + padlength(serverdate.getMinutes()) + ":" + padlength(serverdate.getSeconds())
document.getElementById("_clock").innerHTML = datestring+" " + timestring
}
</script>
EOD;
If I don't try to set the initial value of the date object it seems to work. But when I do it simply does nothing.
Thanks