PDA

View Full Version : count down


adash5000
03-28-2003, 01:18 AM
i got this script that calculates how many days left are til a certain date, ive edit it a little:

<script>

today = new Date()
var eos = new Date(today.getFullYear(), 5, 19)
var one_day=1000*60*60*24

document.write(Math.ceil((eos.getTime()-today.getTime())/(one_day))+
" days left till the last day of school")

</script>

if i put this in a form is there any way i could veiw the countdown
so that its formatted to have days, hours, minutes, and seconds.
:rolleyes:

glenngv
03-28-2003, 03:32 AM
try this:


var eos = new Date(new Date().getFullYear(),5,19);
var one_day=1000*60*60*24;
var timer;

function countDown(){
var today = new Date();
var hours=0;
var mins=0;
var secs=0;
days = (eos.getTime()-today.getTime())/one_day;
if (days>0){
intDays = Math.floor(days);
daysFracPart = getFracPart(days);
if (daysFracPart>0){
hours = daysFracPart*24;
intHours = Math.floor(hours);
hoursFracPart = getFracPart(hours);
if (hoursFracPart>0){
mins = hoursFracPart*60;
intMins = Math.floor(mins);
minsFracPart = getFracPart(mins);
if (minsFracPart>0){
secs = minsFracPart*60;
intSecs = Math.round(secs);
if (intSecs==60) intSecs=0;
}
}
}
window.status = intDays + " days " + intHours + " hours " + intMins + " mins " + intSecs + " secs left till the last day of school.";
}
else{
window.status = "Today is the last day of the school!!!";
if (timer) clearInterval(timer);
}
}

function getFracPart(floatNum){
return parseFloat(floatNum.toString().substring(floatNum.toString().indexOf(".")));
}

timer = setInterval("countDown()",1000);



the countdown is displayed in the status bar.
you can modify it to display inside the form, but remember to call the function onload.

adash5000
03-28-2003, 04:25 AM
hey thanks it worked