码迷,mamicode.com
首页 > Web开发 > 详细

js 倒计时 (时分秒版本)

时间:2016-06-02 09:52:05      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta charset="UTF-8">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>下班倒计时</title>
</head>

<body>
    <div id="msg">
    </div>
</body>
</html>
 <script>
    var endTime = new Date();
    endTime.setHours(9);
    endTime.setMinutes(29);
    endTime.setSeconds(52);


    var getTime = function() 
    {
        var nowTime = new Date();
        var ms = endTime.getTime() - nowTime.getTime();
        var day = Math.floor(ms / (1000 * 60 * 60 * 24));
        var hour = Math.floor(ms / (1000 * 60 * 60)) % 24;
        var minute = Math.floor(ms / (1000 * 60)) % 60;
        var second = Math.floor(ms / 1000) % 60;
        ms = Math.floor(ms / 100) % 10;
        if (day >= 0) {
            document.getElementById("msg").innerHTML = hour + "小时 " + minute + "" + second + ""
        } 
        else 
        {            
            alert("下班了");
           return false;
        }
       setTimeout("getTime()", 1000);
    }
     getTime();
</script>

 

js 倒计时 (时分秒版本)

标签:

原文地址:http://www.cnblogs.com/CyLee/p/5551871.html

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