<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1></h1>
<script type="text/javascript">
// 现在到 2024-12-17的 倒计时
let timer = setInterval(function (){
let sta = new Date().getTime();
// 获取当前的时间戳
let end = new Date('2024-12-17 00:00:00').getTime();
// 获取2024 年12月的时间戳
let and = end-sta; //时间差
if(and >=0){
let d = Math.floor(and/1000/60/60/24); //得到天数
let h = Math.floor(and/1000/60/60%24); //得到小时数
let m = Math.floor(and/1000/60%60); // 得到分钟
let s = Math.floor(and/1000%60); //得到秒
document.querySelector("h1").innerText = `${d}天 ${h}小时 ${m}分 ${s}秒`
}else{
clearInterval(timer);
}
},1000)
</script>
</body>
</html>
标签:60,floor,getTime,倒计时,日期,let,Math,1000
From: https://blog.csdn.net/m0_64455070/article/details/139507729