Can someone make me a simple countdown timer?
It has to repeat.
Like, my server restarts at midnight EST time.
So I need something to countdown to that, then restart as soon as it hits midnight.
I'm to lazy to do it (:
Printable View
Can someone make me a simple countdown timer?
It has to repeat.
Like, my server restarts at midnight EST time.
So I need something to countdown to that, then restart as soon as it hits midnight.
I'm to lazy to do it (:
PHP Code:<script type = "text/javascript">
var timeInSecs;
var ticker;
function startTimer(secs) {
timeInSecs = parseInt(secs);
ticker = setInterval("tick()", 1000);
}
function tick( ) {
var secs = timeInSecs;
if (secs > 0) {
timeInSecs--;
}
else {
clearInterval(ticker);
startTimer(86400); // start again
}
var hours= Math.floor(secs/3600);
secs %= 3600;
var mins = Math.floor(secs/60);
secs %= 60;
var pretty = ( (hours < 10 ) ? "0" : "" ) + hours + ":" + ( (mins < 10) ? "0" : "" ) + mins + ":" + ( (secs < 10) ? "0" : "" ) + secs;
document.getElementById("countdown").innerHTML = pretty;
}
startTimer(86400); // 24 hours in seconds
</script>
<span id="countdown" style="font-weight: bold;"></span>
Thank you sir.
Like and rep if i helped :)
1. Avoid eval at all costs. setInterval will take a function, passing a string invokes eval.
2. Never assume the timing on setInterval or setTimeout is reliable based on the time you give it (ie, passing 1000 may result in ticks that are anywhere from 1ms to 50000000+ ms apart).
3. You don't need to parseInt an integer, and in the event that you are using parseInt, you should indicate the base.
4. This does not take timezone differences into account, whenever you are rendering a time or a timer on a user's browser, it should reliably show the correct time.
Kid, at least post the url where you got that snippet from
Posted via Mobile Device
Off topic - but I had to point it out:
http://i.imgur.com/SELyA.png
^Unintended reverse psychology.
I believe the guy who actually made it would have liked if you included the link where you found it.
(tha link ya know): Need A Repeating Countdown Timer [Archive] - CodingForums.com [POST FROM Philip M, Post number 2]