JS倒计时
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p id="p"></p>
<script>
let p = document.getElementById("p");
setInterval(function () {
var nowtime = new Date();
let year = nowtime.getFullYear();
let month = nowtime.getMonth() + 1;
let days = nowtime.getDate();
let a = year + '/' + month + '/' + days;
var endtime = new Date(a + " 19:00:00");
var seconds = parseInt((endtime - nowtime) / 1000)
var day = fn(parseInt(seconds / 3600 / 24));
var hou = fn(parseInt(seconds / 3600 % 24));
var sec = fn(parseInt(seconds / 60 % 60));
var mil = fn(parseInt(seconds % 60));
console.log(typeof day)
if(day == "00"){
p.innerHTML = hou + "小时" + sec + "分" + mil + "秒"
}else{
p.innerHTML = day + "天" + hou + "小时" + sec + "分" + mil + "秒"
}
}, 1000)
function fn(num) {
if (num < 10) {
return "0" + num
} else {
return num
}
}
</script>
</body>
</html>