Hello,
I need help with setInterval()! Well I have this code to show the current time.
But when I set the interval to 1000 it will take 1 second before it shows the time… This is my code:
[code=html]//Javascript code:
<script type=”text/javascript”>
var serverdate = new Date()
function padlength(string) {
var output = (string.toString().length==1)? “0”+string : string
return output
}
function displaytime() {
serverdate.setSeconds(serverdate.getSeconds()+1)
var timestring = padlength(serverdate.getHours())+”:”+padlength(serverdate.getMinutes())+”:”+padlength(serverdate.getSeconds())
document.getElementById(“servertime”).innerHTML = timestring
}
window.onload = function(){
setInterval(“displaytime()”, 1000);
}
</script>
// HTML part for showing the time:
<a href=”index.php?a=mod_stat_servertime”>Server Time: <span class=”servertime” id=”servertime”></span></a>
Greetz,
Frico