var delay = 1000;
function Timer() {
// do whatever
window.setTimeout(Timer, delay);
}
window.setTimeout(Timer, delay);
<!DOCTYPE html>
A counter that you can Start/Stop/Pause
ReStart
Stop
pause
<!DOCTYPE HTML>
Simple Timer
00:00:00
timer 00:00:00.0
Reset/Start
Stop
pause
d.setHours((d.getHours()-h1),(d.getMinutes()-m1),(d.getSeconds()-s1),(d.getMilliseconds()-mil1));
d.setHours(d.getHours()-h1);
d.setMinutes(d.getMinutes()-m1);
etc.
It's the same just all in one commandOriginally Posted by Zen00
Hey Tom, thanks for posting the article, I read through it and your example code a few times and have started making appropriate changes.
In the mean time, how does this line of code work?
Code:
I couldn't find anything about it in W3Schools, so how does it work better than say...Code:d.setHours((d.getHours()-h1),(d.getMinutes()-m1),(d.getSeconds()-s1),(d.getMilliseconds()-mil1));
Code:
Code:d.setHours(d.getHours()-h1); d.setMinutes(d.getMinutes()-m1); etc.
Date.setHours(hour,min,sec,millisec)
<!DOCTYPE HTML>
Simple Timer
00:00:00
how to use timer without buttons in the above code...like for example if we only open the page then timer starts and pauses when its not in use...Originally Posted by tom.slick
The way we are doing it now is not the best way to do this. It does not keep proper time. I found an article that explains why http://www.sitepoint.com/creating-accurate-timers-in-javascript/
The author is right, I added a clock to your example page and it quickly went out of sync. So I rewrote my example and it seems to be a lot more accurate.
Code:
Code:timer 00:00:00.0 Reset/Start Stop pause