A very precise countdown
Want to know how long you have to wait before a specific event occurs? This countdown is provided in real-time and to the
nearest second, telling you how long it is until... Easter for example.
To create this countdown, first copy the following script in the header of your page. Simply specify the countdown reference
date in English form. Here, we have chosen Easter at midnight (
Apr 14 2002 00:00:00). You can also personalize the script display text:
<SCRIPT LANGUAGE="JavaScript">
<!--
function getTime() {
now = new Date();
y2k = new Date("Dec 25 2002 00:00:00");
days = (y2k - now) / 1000 / 60 / 60 / 24;
daysRound = Math.floor(days);
hours = (y2k - now) / 1000 / 60 / 60 - (24 * daysRound);
hoursRound = Math.floor(hours);
minutes = (y2k - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
minutesRound = Math.floor(minutes);
seconds = (y2k - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);
sec = (secondsRound == 1) ? " second" : " seconds";
min = (minutesRound == 1) ? " minute" : " minutes, ";
hr = (hoursRound == 1) ? " hour" : " hours, ";
dy = (daysRound == 1) ? " day" : " days, "
document.timeForm.input1.value = "There's " + daysRound + dy + hoursRound + hr + minutesRound + min + secondsRound + sec + " before next Xmas!";
newtime = window.setTimeout("getTime();", 1000);
}
// -->
</script>
Then, go to your page and insert the form that will display the countdown. This is a simple text field in the following form:
<form name=timeForm>
<input type="texte" name=input1 size=110 border-style="none" style="border-bottom: 0px solid; border-left: 0px solid;border-right:
0px solid;border-top: 0px solid;font:12px arial, helvetica,sans-serif">
</form>
Now all you have to do is launch execution of the script using the
onLoad attribute of the
<body> tag of your page. Child's play:
<BODY onLoad="getTime()">
Now you know how long you have to wait before you can eat your chocolate Easter bunny.
Discover all Webmaster tips.