天时分秒毫秒倒计时


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>时间倒计时</title>
    <style>
        div{
            margin: 100px auto;
            font:bold 60px "仿宋";
        }
    </style>
</head>
<body>
<script>
    function t( n ) {
        if( n > 9 ){
            return n;
        }else{
            return "0"+n;
        }
    }

    function timer ( year, month, day, divId) {
        var nowDate = new Date();
        var endDate = new Date( year, month-1, day );
        var cerDate = endDate.getTime() - nowDate.getTime();
        var cerTime = parseInt(cerDate / 1000);
        var dd = Math.floor( cerTime /(60*60*24));
        var hour = Math.floor( (cerTime - dd *60*60*24)/3600);
        var minute = Math.floor( (cerTime - dd *60*60*24 - hour * 60*60)/60);
        var second = Math.floor( (cerTime - dd *60*60*24 - hour * 60*60 - minute *60) );
        var ms  = Math.floor(parseInt(cerDate / 10)%60);

        var oDiv = document.getElementById( divId );
        oDiv.innerHTML = "距离规定时间"+ t( year )+ ""+ t(month)+""+ t(day)+"日还有:"+ t(dd)+""+t(hour)
            +""+t(minute)+""+t(second)+""+ t(ms);

    }
    window.setInterval(function(){
        timer( 2017, 12, 16, "txt")
    },10)
</script>
<div id="txt"></div>
</body>
</html>

 

posted @ 2017-06-05 16:53  曦言鸢默  阅读(574)  评论(0编辑  收藏  举报