<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
text-align: center;
}
.title {
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<h2 class="title" id="title"></h2>
<h3 id="distance-time"></h3>
<script>
const dom = document.getElementById("distance-time");
const title = document.getElementById("title");
title.innerText = `距离${new Date().getFullYear()}年春节还有`;
function getTime() {
const now = Date.now();
const end = new Date("2024-2-10 00:00:00");
console.log("🚀 ~ file: 春节倒计时.html:20 ~ end:", end.getTime());
const distance = Math.round((end - now) / 1000);
const sec = distance % 60;
const allMinus = (distance - sec) / 60;
const minus = allMinus % 60;
const allHour = (allMinus - minus) / 60;
const hour = allHour % 24;
const day = (allHour - hour) / 24;
dom.innerText = `距离春节还有:${day}天${hour}小时${minus}分钟${sec}秒`;
}
getTime();
setInterval(() => {
getTime();
}, 1000);
</script>
</body>
</html>
11-26
12-04
696

12-11
1万+
