<style>
span{
border: 1px solid #ccc;
}
</style>
</head>
<body>
<div id="cjl">
<span id="cjl1"></span>
<span id="cjl2"></span>
<span id="cjl3"></span>
<span id="cjl4"></span>
<span id="cjl5"></span>
</div>
</body>
<script>
setInterval(function show() {
var date =new Date();
var year = date.getFullYear();
var month = date.getMonth()+1;
var days = date.getDate();
var hour = date.getHours();
var mins = date.getMinutes();
var secs = date.getSeconds();
var week = date.getDay();
var nowtime =new Date().getTime();
console.log(nowtime)
var weilaiTime = new Date("2022/03/21 09:00:00")
var weilais = weilaiTime.getTime();
console.log(weilais)
var time =Math.round ((weilais - nowtime)/1000)
console.log(time) //秒
var day =parseInt (time/(24*3600));
console.log(day)
var shi =parseInt (time/(3600)-(day*24))
console.log(shi)
var fen =parseInt (time/(60)-(day*24*60+shi*60))
console.log(fen)
var miao =parseInt (time-(day*24*3600+shi*3600+fen*60))
console.log(miao)
document.getElementById("cjl1").innerHTML=("距离周一上午8:30分:")
document.getElementById("cjl2").innerHTML=(day+'天')
document.getElementById("cjl3").innerHTML=(shi+"时")
document.getElementById("cjl4").innerHTML=(fen+"分")
document.getElementById("cjl5").innerHTML=(miao+"秒")
}, 1000);
</script>
从当前时间到设置时间的时间差