<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>倒计时制作</title><style>div{width:500px;height:100px;font-size:20px;margin: 200px auto;//200px默认是上边距/*border:1px solid red;*/}</style></head>
<body>
<div>距离2020年8月1号还有:<span id="d"></span>天<span id="h"></span>时<span id="m"></span>分<span id="s"></span>秒</div>
<script>function move(){var nowTime =new Date().getTime();//获取当前的毫秒数var wTime =new Date("2020,8,1").getTime();//获取指定日期的毫秒数var leftTime =(wTime-nowTime)/1000;//获取两者相差的秒数var day =parseInt(leftTime/60/60/24);//转化为天数var hour =parseInt(leftTime/60/60%24);//转化为小时var minute =parseInt(leftTime/60%60);//转化为分钟var second =parseInt(leftTime%60);//转化为秒数document.getElementById("d").innerHTML=day;document.getElementById("h").innerHTML=hour;document.getElementById("m").innerHTML=minute;document.getElementById("s").innerHTML=second;}move();setInterval(move,1000);
</script>
</body>
</html>