<!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>
<body>
<h1 id="h"></h1>
<script>
var date = new Date('2021-9-9 18:0:0') //(输入指定的时间)
djs(date)
var t = setInterval(function () {
djs(date)
}, 1000)
function djs(date1) {
console.log(date1);
var date2 = new Date();
// 时间可以求减法 得到的是毫秒数
var gap = parseInt((date1 - date2) / 1000);
console.log(gap);
var hour = parseInt(gap / 3600);
var min = parseInt(gap % 3600 / 60);
var sec = gap % 60;
var oH = document.getElementById('h');
oH.innerHTML = `距离下课还有${hour}:${min}:${sec}`
}
</script>
</body>
</html>