2024春节倒计时html
时间: 2023-11-15 13:55:11 浏览: 291
以下是一个简单的倒计时HTML代码,可以用于2024年春节倒计时:
```html
<!DOCTYPE html>
<html>
<head>
<title>2024春节倒计时</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f2f2f2;
}
h1 {
font-size: 3em;
margin-top: 50px;
}
p {
font-size: 2em;
margin-top: 20px;
}
</style>
</head>
<body>
<h1>2024春节倒计时</h1>
<p id="countdown"></p>
<script type="text/javascript">
var countDownDate = new Date("Feb 5, 2024 00:00:00").getTime();
var x = setInterval(function() {
var now = new Date().getTime();
var distance = countDownDate - now;
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById("countdown").innerHTML = days + " 天 " + hours + " 小时 "
+ minutes + " 分钟 " + seconds + " 秒 ";
if (distance < 0) {
clearInterval(x);
document.getElementById("countdown").innerHTML = "春节快乐!";
}
}, 1000);
</script>
</body>
</html>
```
阅读全文