<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
div {
margin: 200px;
}
span {
/* 转换为行内块元素 */
display: inline-block;
width: 40px;
height: 40px;
background-color: #333;
font-size: 20px;
color: #fff;
text-align: center;
line-height: 40px;
}
</style>
</style>
<body>
<div>
<span class="hour">时</span>
<span class="minute">分</span>
<span class="second">秒</span>
</div>
<script>
var hour=document.querySelector('.hour');
var minute=document.querySelector('.minute');
var second=document.querySelector('.second');
function countDown(){
var inputTime=+new Date('2022-4-22 22:00:00');
var nowTime=new Date();
var times=(inputTime-nowTime)/1000;
var h=parseInt(times / 60 / 60 % 24);
h=h<10 ? '0'+ h : h;
hour.innerHTML=h;
var m=parseInt(times / 60 % 60);
h=h<10 ? '0'+ m : m;
minute.innerHTML=m;
var s=parseInt(times % 60);
h=h<10 ? '0'+ s : s;
second.innerHTML=s;
}
countDown();
setInterval(countDown,1000);
</script>
</body>
</html>
08-26
1193
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-27
1500
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)