2024-06-27
藏龙卧虎
00
请注意,本文编写于 72 天前,最后修改于 72 天前,其中某些信息可能已经过时。

提示:以下代码拷贝到本地,填入新建的 .html 文件,使用浏览器打开即可预览效果。

html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Countdown to Midnight</title> <style> #countdown { font-size: 4em; color: #333; text-align: center; } </style> </head> <body> <div id="countdown">倒计时:00:00:00</div> <script> function updateCountdown() { // 获取当前时间 const now = new Date(); // 获取明天00:00的时间 const tomorrow = new Date(); tomorrow.setHours(24, 0, 0, 0); // 计算时间差(毫秒) const timeDifference = tomorrow - now; // 计算剩余的小时、分钟和秒 const hours = Math.floor((timeDifference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); const minutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60)); const seconds = Math.floor((timeDifference % (1000 * 60)) / 1000); // 格式化时间 const formattedHours = hours.toString().padStart(2, '0'); const formattedMinutes = minutes.toString().padStart(2, '0'); const formattedSeconds = seconds.toString().padStart(2, '0'); // 更新倒计时显示 document.getElementById('countdown').textContent = `DLC解锁倒计时:${formattedHours}:${formattedMinutes}:${formattedSeconds}`; } // 每秒更新一次倒计时 setInterval(updateCountdown, 1000); // 初次调用,避免页面加载时的延迟 updateCountdown(); </script> </body> </html>
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:DingDangDog

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!