Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1204 How can I count down in seconds from the current time to the year 2000?

irt.org | Knowledge Base | JavaScript | Date | Q1204 [ previous next ]

Q1204 How can I count down in seconds from the current time to the year 2000?

Try:

<script language="JavaScript"><!--
var y2kms = (new Date(2000,0,1,0,0,0)).getTime();

function tick() {
    var nowms = (new Date()).getTime();
        var temp;
    if (y2kms > nowms) {
            temp = Math.floor((y2kms - nowms)/1000);
                if (document.myForm.myCount.value != temp)
                    document.myForm.myCount.value = temp;
        setTimeout('tick()',500);
    }
        else
            alert('BANG!');
}
//--></script>

<body onLoad="tick()">

<form name="myForm">
<input type="text" name="myCount">
</form>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.