zoukankan      html  css  js  c++  java
  • JS倒计时精确到毫秒

    <!DOCTYPE html>
    <html lang="zh-cn">
    <head>
        <meta charset="UTF-8">
        <title>倒计时精确到毫秒</title>
        <style>
        #timer {
            height:50px;
            width:100%;
            text-align:center;
            line-height:50px;
            background:black;
            color:white;
        }
        </style>
        <script>
        function countDown(dd) {
            var t = new Date(dd),
            n = new Date().getTime(),
            c = t - n;
    
            // 结束执行
            if (c <= 0) {
                clearInterval(window['timer']);
                return;
            }
    
            d = parseInt(c / 1000 / 60 / 60 / 24),
            h = parseInt(c / 1000 / 60 / 60 - (24 * d)),
            m = parseInt(c / 1000 / 60 - (24 * 60 * d) - (60 * h)),
            s = parseInt(c / 1000 - (24 * 60 * 60 * d) - (60 * 60 * h) - (60 * m));
            hm = Math.floor((c - (24 * 60 * 60 * 1000 * d) - (60 * 60 * 1000 * h) - (60 * 1000 * m) - (s * 1000)) / 10);
    
            if (hm < 10) {hm = "0" + hm;}
            if (s < 10) {s = "0" + s;}
            if (m < 10) {m = "0" + m;}
            if (h < 10) {h = "0" + h;}
    
            document.getElementById('timer').innerHTML = '距离2118年10月1日还有:' + d + '' + h + '小时' + m + '分钟' + s + '' + hm + '毫秒';
        }
        (function() {
            window['timer'] = setInterval(function() {
                countDown('2118/10/1 00:00:00:00');
            }, 50);
        })();
        </script>
    </head>
    <body>
        <div id="timer"></div>
    </body>
    </html>
  • 相关阅读:
    「CSP模拟」模拟测试6
    「CSP模拟」模拟测试5
    镇黑板
    求和「Dirichlet 前缀和」
    二叉搜索树「区间DP」
    序列
    [CSP模拟]异或帽子+传话游戏+全球覆盖+幂次序列
    MySQL常用引擎及优缺点
    Django项目远程开发环境搭建
    MySQL8.0安装与配置
  • 原文地址:https://www.cnblogs.com/chenjiacheng/p/7228571.html
Copyright © 2011-2022 走看看