zoukankan      html  css  js  c++  java
  • js倒计时

        <div class="timeWrap">
            <span id="day"></span><span id="hours"></span><span id="minute"></span><span id="second"></span></div>
        /* 倒计时 */
        function countNum(time) {
           let day = document.getElementById('day')
           let hours = document.getElementById('hours')
           let minute = document.getElementById('minute')
           let second = document.getElementById('second')
           function fillZero(time) {
               return time < 10 ? '0' + time : time
           }
           setInterval(() => {
                let selfSetTime = new Date(time)
                let nowTime = new Date()
                let surplus = (selfSetTime - nowTime) / 1000
                let d = fillZero(parseInt(surplus / 60 / 60 /24))
                let h = fillZero(parseInt(surplus / 60 / 60 % 24))
                let m = fillZero(parseInt(surplus / 60 % 60))
                let s = fillZero(parseInt(surplus % 60))
                day.innerHTML = d
                hours.innerHTML = h
                minute.innerHTML = m
                second.innerHTML = s
           }, 1000);
          
        }
        
        countNum('2021-09-02 16:00:00')    
  • 相关阅读:
    随机数模块(random)
    时间模块(time)
    collection模块 1
    collection模块
    re模块
    正则
    Bootstrap 关于下拉菜单的使用
    Bootstrap 关于Glyphicons 字体图标的使用
    oracle拼音排序
    ajax缓存问题
  • 原文地址:https://www.cnblogs.com/vokiinnn/p/15219079.html
Copyright © 2011-2022 走看看