欧洲杯决赛倒计时
body {
fontfamily: Arial, sansserif;
margin: 20px;
}
h1 {
textalign: center;
}
.countdown {
textalign: center;
fontsize: 24px;
margintop: 50px;
}
// 设置欧洲杯决赛日期
const finalDate = new Date('20240714T00:00:00');
function updateCountdown() {
const currentDate = new Date();
const difference = finalDate currentDate;
if (difference <= 0) {
document.getElementById('countdown').innerHTML = "决赛已经开始!";
} else {
const days = Math.floor(difference / (1000 * 60 * 60 * 24));
document.getElementById('countdown').innerHTML = `距离决赛还有 ${days} 天`;
}
}
// 初始调用一次
updateCountdown();
// 每秒更新一次
setInterval(updateCountdown, 1000);