Blogger Information
Blog 4
fans 0
comment 0
visits 2733
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
春节倒计时2019/01/21
夏雪忆梦的博客
Original
774 people have browsed it

主要用到了,getTime()函数,var nowtime = new Date();得到现在时间, var future = new Date("2019/02/05 00:00:00");

得到将来时间,,var timeSum = future.getTime() - nowtime.getTime();得到秒数

实例

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        div {
            width: 1210px;
            margin: 200px auto;
            color: red;
            text-align: center;
            font: 600 30px/30px "simsun";
        }
    </style>
</head>
<body>
    <div></div>

<script>
    var div=document.getElementsByTagName("div")[0];
    var timer = setInterval(fn,1);
    function fn(){
        var nowtime = new Date();
//      console.log(nowtime);
        var future = new Date("2019/02/05 00:00:00");
//      console.log(future);
        var timeSum = future.getTime() - nowtime.getTime();
//      console.log(timeSum)
        var day = parseInt(timeSum/1000/60/60/24);
        var hour = parseInt(timeSum/1000/60/60%24);
        var minu = parseInt(timeSum/1000/60%60);
        var sec = parseInt(timeSum/1000%60);
        var millsec = parseInt(timeSum%1000);
        day=day<10?"0"+day:day;
        hour=hour<10?"0"+hour:hour;
        minu=minu<10?"0"+minu:minu;
        sec=sec<10?"0"+sec:sec;
        if(millsec<10){
            millsec="00"+millsec;
        }else if(millsec<100){
            millsec="0"+millsec;
        }
//
//        console.log(day);
//        console.log(parseInt(timeSum/1000/60/60/24));
        if(timeSum<0){
            div.innerHTML="距离春节还有00天00小时00分00秒000毫秒";
            clearInterval(timer);
            return;
        }
        div.innerHTML="距离春节还有"+day+"天"+hour+"小时"+minu+"分"+sec+"秒"+millsec+"毫秒";
        // console.log(future);
    }
   

</script>
</body>

</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post