html部分
<div>距离开始时间还剩
<span class="syday"></span>天
<span class="syhour"></span>时
<span class="symin"></span>分
<span class="sysen"></span>秒
</div>
js部分
let countdown = function (){
var syday = document.querySelector('.syday')
var syhour = document.querySelector('.syhour')
var symin = document.querySelector('.symin')
var sysen = document.querySelector('.sysen')
let nowTime = +new Date(); //现在时间
let msTime = +new Date('2021-12-25 16:00:00'); //秒杀时间
setInterval(countdown,1000);
let syTime = (msTime - nowTime) / 1000; //距离秒杀的剩余时间
let d = parseInt(syTime /60/60/24);
d = d < 10 ? '0' + d : d;
syday.innerHTML = d;
let h = parseInt(syTime /60/60%24);
h = h < 10 ? '0' + h : h;
syhour.innerHTML = h;
let m = parseInt(syTime /60%60);
m = m < 10 ? '0' + m : m;
symin.innerHTML = m;
let s = parseInt(syTime %60);
s = s < 10 ? '0' + s : s;
sysen.innerHTML = s;
}