一、效果图
二、核心代码
window.onload=function(){ //倒计时的时间 var dtime=new Date("2021/11/29 00:00:00"); time=setInterval(function(){ //获取当前的时间 var ntime=new Date(); var c=dtime.getTime()-ntime.getTime(); //总差进行换算 var day = parseInt(c / (1000 * 60 * 60 * 24)); var hour=parseInt((c % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var min=parseInt((c % (1000 * 60 * 60)) / (1000 * 60)); var sec=parseInt((c % (1000 * 60)) / 1000); a.innerHTML = day + "日"; b.innerHTML = hour + "时"; d.innerHTML = min + "分"; e.innerHTML = sec + "秒"; },1000) }