Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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

You are here: irt.org | FAQ | JavaScript | Date | Q1204 [ previous next ]

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>

©2018 Martin Webb