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')