倒计时

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div class="time"></div>
<script src="jquery-1.11.3.min.js"></script>
<script>
    //倒计时
    window.setInterval(function(){
        var startTime=new Date("2016/7/21 16:32:10");
        /* var endTime=new Date("2016/6/20 12:32:10");*/
        var endTime=new Date();
        var startSeconds=startTime.getTime();
        var endSeconds=endTime.getTime();
        var spanTime=startSeconds-endSeconds;
        var time=document.getElementsByClassName("time")[0];
        if(spanTime>0){
            var day=Math.floor(spanTime/(1000*60*60*24));
            var hours=Math.floor(spanTime/(1000*60*60))%24;
            var minutes=Math.floor(spanTime/(1000*60))%60;
            var seconds=Math.floor(spanTime/1000)%60;
            time.innerHTML="距离活动还剩:"+zero(day)+""+zero(hours)+"小时"+zero(minutes)+""+zero(seconds)+"";
        }else{
            time.innerHTML="活动已结束!";
        }

    },1000);

    function zero(num){
        return num<10?"0"+num:num;
    }

</script>
</body>
</html>

 

posted @ 2016-08-08 16:21  dongxiaolei  阅读(164)  评论(0编辑  收藏  举报