Forum Moderators: mack
141 days 2 hours and 22 seconds till XYZ event
I saw some java script that canculate time difference but I want a clock that counds down real time, maybe every 15 seconds or so.
The server calculates "seconds" at page generation time, so you may have to add some code to calculate the number of seconds remaining if you're not going to do it server side...
Here's the code - modified off the top of my head to include days, but it should be ok....
<script type='text/javascipr'>
var seconds = 42772;
function countdown()
{
var t,d,h,m,s;t = seconds;
d = parseInt(t / 86400);
t = t - (d * 86400);
h = parseInt(t / 3600);
t = t - (h * 3600);
m = parseInt(t / 60);
t = t - (m * 60);
s = parseInt(t);
document.getElementById("d").innerHTML = d;
document.getElementById("h").innerHTML = h;
document.getElementById("m").innerHTML = m;
document.getElementById("s").innerHTML = s;
seconds = seconds - 1;
if (seconds > -1) window.setTimeout("countdown()",1000);
}countdown();
</script>
<div id='d'></div> DAYS
<div id='h'></div> HOURS
<div id='m'></div> MINUTES
<div id='s'></div> SECONDS
Should give you the mechanics. Good luck!