码迷,mamicode.com
首页 > 其他好文 > 详细

倒计时

时间:2016-09-12 12:11:31      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>北京时间</title>
</head>
<style>
    *{
        margin: 0;
        padding: 0;
        list-style: none;
        color: red;
    }
    #time,#time2,#time3{
        width: 800px;
        height: 100px;
        line-height: 100px;
        font-size: 30px;
        font-family: "微软雅黑";
        position: absolute;
        margin: auto;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.4);
        box-shadow: 0px 0px 10px #000;
        text-align: center;
    }
    #time{
        top: 0;
    }
    #time2{
        top: 30%;
    }
    #time3{
        top: -30%;
    }
</style>
<body>
    <div id="time"></div>
    <div id="time2"></div>
    <div id="time3"></div>
</body>
<script>
    window.onload = function(){
        times();
        function times(){
            showTime();    
            function minSecond(i){
                if(i<10){
                    i = "0" + i; 
                }
                return i;
            }
            function showTime(){
                var bjtime = new Date();
                var bjyear = bjtime.getFullYear();
                var bjmonth = bjtime.getMonth()+1;
                var bjday = bjtime.getDate();
                var week = bjtime.getDay();
                var hours = bjtime.getHours();
                var min = bjtime.getMinutes();
                var seconds = bjtime.getSeconds();
                min = minSecond(min);
                seconds = minSecond(seconds);
                var weekday = ["","","","","",""];
                
                document.getElementById("time").innerHTML ="现在是北京时间:" + bjyear +"年-"+ bjmonth +"月-"+ bjday +"日-" + "星期" + weekday[week] + "-" + hours +":" + min +":"+ seconds  ;
                setInterval(showTime,1000);
            }
        }

        var curtime = new Date();
        var endtime = new Date("2016,10,1");
        var lefttimeday = Math.floor((endtime.getTime() - curtime.getTime())/(24*60*60*1000));
        document.getElementById("time2").innerHTML = "距离国庆还有:" + lefttimeday + "";




        showTime2();
        
        function showTime2(){
            var nowtime = new Date();
            var endtime2 = new Date("2017/1/1,00:00:00");
            var chatime = parseInt((endtime2.getTime() - nowtime.getTime())/1000);
            var d = parseInt(chatime/(24*60*60));
            var h = parseInt(chatime/(60*60)%24);
            var m = parseInt(chatime/60%60);
            var s = parseInt(chatime%60);
            document.getElementById("time3").innerHTML = "距离元旦还有:" + d + "" + h + "小时" + m + "分钟" + s + ""; 
            if(chatime<=0){
                document.getElementById("time3").innerHTML = "身份证到期了";
            }else{
                setInterval(showTime2,1000);
            }
        }
    }
</script>
</html>

技术分享

倒计时

标签:

原文地址:http://www.cnblogs.com/mymission/p/5864241.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!