运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <p>The weekend is only <span id="weekend_coundown"></span> from now!</p> <script> function countdownToSaturday() { var now = new Date(); var dayOfWeek = now.getDay(); //0-6 where 0 is Sunday, 6 is Saturday var daysToSaturday = (dayOfWeek < 6) ? (6 - dayOfWeek) : 0; // if it's already Saturday, no days remain var currentHour = now.getHours(); var hoursToSaturday = 0; // If it's not Saturday or if it's Saturday but before 12:00 (noon), // consider the remaining hours to Saturday noon if (daysToSaturday > 0 || (daysToSaturday === 0 && currentHour < 12)) { hoursToSaturday = (24 - currentHour + 12) % 24; } var days = daysToSaturday > 0 ? daysToSaturday + " day(s), " : ""; var hours = hoursToSaturday > 0 ? hoursToSaturday + " hour(s)" : ""; // if it's Saturday and past 12:00 (noon), the countdown should return 0. if (daysToSaturday === 0 && currentHour >= 12) { days = ""; hours = "0 hours"; } document.getElementById('weekend_coundown').innerText = days + hours; } countdownToSaturday(); setInterval(countdownToSaturday, 1000 * 60 * 60); // update the countdown every hour </script> </body> </html>