This is an example for the 2012 end of the world:
<body onload="frundate();rundate();">
December 21st 2012 is near!
<br /><br />
<span id="d"></span> days : <span id="h"></span> hours :
<span id="m"></span> mins : <span id="s"></span> secs left
<script type="text/javascript">
/*this is to set the "limit" date*/
var t = new Date();
ly=2012;
lm=11;
ld=21;
lh=0;
lmn=0;
ls=0;
t.setFullYear(ly,lm,ld);
t.setUTCHours(lh,lmn,ls);
totals=Math.ceil(t.getTime()/1000);
/*this is to get the current date*/
var today = new Date();
todays=Math.ceil(today.getTime()/1000);
/*now we find the seconds between the 2 dates*/
secondsl=totals-todays;
/*arithmetic to find days, hours, etc.*/
fd=Math.floor(secondsl/86400);
sr=secondsl-fd*86400;
fh=Math.floor(sr/3600);
sr=sr-fh*3600;
fm=Math.floor(sr/60);
fs=sr-fm*60;
fr=fd+':'+fh+':'+fm+':'+fs;
/*this functions fills the contdown spaces*/
function frundate()
{
document.getElementById('d').innerHTML=fd;
document.getElementById('h').innerHTML=fh;
document.getElementById('m').innerHTML=fm;
document.getElementById('s').innerHTML=fs;
}
/*this is the "clock"*/
function rundate()
{
time=setTimeout("rundate()",1000);
fs=fs-1;
if(fs<0)
{
fs=59;
fm=fm-1;
}
document.getElementById('s').innerHTML=fs;
if(fm<0)
{
fm=59;
fh=fh-1;
}
document.getElementById('m').innerHTML=fm;
if(fh<0)
{
fh=23;
fd=fd-1;
}
document.getElementById('h').innerHTML=fh;
if(fd<0)
{
fd=0;
document.getElementById('d').innerHTML=fd;
alert('2012 is here!');
return false;
}
}
</script>