FREE COUNTDOWN CLOCK CODE
Description: A versatile and practical script that can be used to count down until any given date.
Example:
Directions: Simply insert the below into the <body> section of your page:
<script>
/*
Count down until any date script-
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
*/
//change the text below to reflect your own,
var before="Valentines day!"
var current="Today is Valentines day. Don\'t forget the flowers!"
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
function countdown(yr,m,d){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy
var futurestring=montharray[m-1]+" "+d+", "+yr
var difference=(Math.round((Date.parse(futurestring)-Date.parse(todaystring))/(24*60*60*1000))*1)
if (difference==0)
document.write(current)
else if (difference>0)
document.write("Only "+difference+" days until "+before)
}
//enter the count down date using the format year/month/day
countdown(2002,2,14)
</script>
There are two areas of the script you'll need to configure. The first is obviously the date you wish the script to count down to. Simply pass in a date, in the form of year, month, and day, into function countdown(), located at the last line of the script:
countdown(2003,2,14)
The second concerns the text to be displayed during the duration of the countdown.
This is affected by the lines:
var before="Christmas!"
var current="Today is Christmas. Merry Christmas!"
The first variable (var before) specifies the key word that will be used to display the sentence ""Only so and so days until ____." The second variable specifies the text to be displayed when the counter has expired (the specified countdown-to date).
If we were to believe Hollywood everytime they ran around yelling the sky is falling we would all be in a lot of trouble.