Click to See Complete Forum and Search --> : countdown timer with hundredths


csheldon
10-06-2003, 02:05 PM
help here please...

looking for a countdown timer that will display...
minutes
seconds
tenths
hundredths

any help would be appreciated...

thanks, chuck

AdamGundry
10-06-2003, 02:16 PM
Something like this? (Not the most efficient, and perhaps could be sped up a little):

<script type="text/javascript">
document.write('<span id="countdownDays"></span> days,
<span id="countdownHours"></span> hours,
<span id="countdownMinutes"></span> minutes,
<span id="countdownSeconds"></span> seconds and
<span id="countdownHundredths"></span> hundredths of a second until 2004.');

var target = new Date(2004, 0, 1);

setInterval("countdown()", 10);

function countdown(){
var now = new Date();
var milliseconds = target - now;

var days = Math.floor(milliseconds / 86400000);
milliseconds-=days*86400000;

var hours = Math.floor(milliseconds / 3600000);
milliseconds-=hours*3600000;

var minutes = Math.floor(milliseconds / 60000);
milliseconds -= minutes*60000;

var seconds = Math.floor(milliseconds / 1000);
milliseconds -= seconds*1000;

var hundredths = Math.floor(milliseconds / 10);

document.getElementById('countdownDays').innerHTML = days;
document.getElementById('countdownHours').innerHTML = hours;
document.getElementById('countdownMinutes').innerHTML = minutes;
document.getElementById('countdownSeconds').innerHTML = seconds;
document.getElementById('countdownHundredths').innerHTML = hundredths;
}
</script>

Adam