Closed Bystroushaak closed 6 years ago
Also is there a reason why you use setTimeout in this recursive manner and not setInterval?
Yes, setTimeout only fires once, and that's all I need.
But it is not, it is called recursively. I mean, instead of
function timeDate() {
var today = new Date();
document.getElementById("time").innerHTML = today.toTimeString().slice(0, 8);
document.getElementById("date").innerHTML = today.toDateString();
var updateTime = setTimeout("timeDate()", 200);
}
you can do
function timeDate() {
var today = new Date();
document.getElementById("time").innerHTML = today.toTimeString().slice(0, 8);
document.getElementById("date").innerHTML = today.toDateString();
}
setInterval(timeDate, 200);
It should be slightly more efficient.
Ok i see what you mean, will use setInterval instead :+1:
Now i remember why i used setTimeout recursively setInterval(timeDate, 200); does not update the clock properly and it lags behind
Thanks :+1: