javascript倒计时

将下面的代码加入到<body>中,既可以看到效果了

<script language="JavaScript" type="text/JavaScript">
    var now=new Date('10/09/2059');
    function showTimeLimit(){
        var future= new Date();
        future-=1000;
        days = (now-future) / 1000 / 60 / 60 / 24;
        dayNum = Math.floor(days);
        hours = (now-future) / 1000 / 60 / 60 - (24 * dayNum);
        houNum = Math.floor(hours);
        if(houNum < 10){
            houNum = "0" + houNum;
        }
        minutes = (now-future) / 1000 / 60 - (24 * 60 * dayNum) - (60 * houNum);
        minNum = Math.floor(minutes);
        if(minNum < 10){
            minNum = "0" + minNum;
        }
        seconds = (now-future) / 1000 - (24 * 60 * 60 * dayNum) - (60 * 60 * houNum) - (60 * minNum);
        secNum = Math.floor(seconds);
        if(secNum < 10){
            secNum = "0" + secNum;
        }
        millisec=(now-future)-(24*60*60*1000*dayNum)-(60*60*1000*houNum)-(60*1000*minNum)-(secNum*1000);
        milli=Math.floor(millisec/10);
        if(milli<10){
            milli="0"+milli;
        }
        document.getElementById('TimeLimit').innerHTML = dayNum+"天"+ houNum + "小时" + minNum + "分"+ secNum + "秒"+milli;
    }
</script>

    <div id="mainContent">
        <DIV id='TimeLimit' style='font-size:16px;font-weight:bold;'></DIV>
        <script language=javascript>setInterval('showTimeLimit()',50);</script>
    </div>

你可能感兴趣的:(JavaScript)