взято с
https://www.bloke.com/javascript/Countdown/
<script language="javascript">
<!-- Countdown in Java Script .. Cameron Gregory
https://www.bloke.com/
// permission to use and modify as long as you leave these 4 comment
// lines in tact and unmodified.
//
https://www.bloke.com/javascript/Countdown/
speed=1000;
len=40;
tid = 0;
num=0;
clockA = new Array();
timeA = new Array();
formatA = new Array();
dd = new Date();
var d,x;
function doDate(x)
{
for (i=0;i<num;i++) {
dt = new Date();
if (timeA[i] != 0) {
v1 = Math.round(( timeA[i] - dt )/1000) ;
if (v1 < 0)
clockA[i].date.value = "**BANG!**";
if (formatA[i] == 1)
clockA[i].date.value = v1;
else if (formatA[i] ==2) {
sec = v1%60;
v1 = Math.floor( v1/60);
min = v1 %60 ;
hour = Math.floor(v1 / 60);
if (sec < 10 ) sec = "0"+sec;
if (min < 10 ) min = "0"+min;
clockA[i].date.value = hour+"h "+min+"m "+sec+"s";
}
else if (formatA[i] ==3) {
sec = v1%60;
v1 = Math.floor( v1/60);
min = v1 %60 ;
v1 = Math.floor(v1 / 60);
hour = v1 %24 ;
day = Math.floor(v1 / 24);
if (sec < 10 ) sec = "0"+sec;
if (min < 10 ) min = "0"+min;
if (hour < 10 ) hour = "0"+hour;
clockA[i].date.value = day+"d "+hour+"h "+min+"m "+sec+"s";
}
else if (formatA[i] ==4 ) {
sec = v1%60;
v1 = Math.floor( v1/60);
min = v1 %60 ;
v1 = Math.floor(v1 / 60);
hour = v1 %24 ;
day = Math.floor(v1 / 24);
clockA[i].date.value = day+(day==1?"day ":"days ")+hour+(hour==1?"hour ":"hours ")+min+(min==1?"min ":"mins ")+sec+(sec==1?"sec ":"secs ")
}
else
clockA[i].date.value = "Invalid Format spec";
}
else
clockA[i].date.value = "Countdown till when?";
}
tid=window.setTimeout("doDate()",speed);
}
function start(d,x,format) {
clockA[num] = x
timeA[num] = new Date(d);
formatA[num] = format;
//window.alert(timeA[num]+":"+d);
if (num == 0)
tid=window.setTimeout("doDate()",speed);
num++;
}
function CountdownLong(t,format,len)
{
document.write('<FORM name=form'+num+'><input name=date size=')
document.write(len)
document.write(' value="Countdown: Requires Javascript"></FORM>')
start(t,document.forms["form"+num],format);
}
// end-->
</script>
<script language="javascript">
// when I'll turn 100, causing my own y1c problems.
CountdownLong("October 15, 2011 00:00:00",1,30);
</script>