首页 > Web开发 > 详细

js倒计时

时间:2020-03-28 22:17:57      阅读:72      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>倒计时</title>
</head>

<body>
    <script>
        // 格式化00
        function forMat(t) {
            return t < 10 ? "0" + t : t
        }

        function countDown(time) {
            var currentTime = +new Date()
            var futureTime = new Date(time)
            var times = futureTime - currentTime
            times = times / 1000 //得到时间戳-秒
            var d = forMat(parseInt(times / 60 / 60 / 24)) //
            var h = forMat(parseInt(times / 60 / 60 % 24)) //
            var s = forMat(parseInt(times / 60 % 60)) //
            var m = forMat(parseInt(times % 60)) //
            return d + "" + h + "" + s + "" + m + ""
        }
        console.log(countDown("2020-5-4 00:00:00"));
    </script>
</body>

</html>

 

js倒计时

原文:https://www.cnblogs.com/zwnsyw/p/12589625.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!