小時

分鐘

// 設定目標日期為2024年1月13日 var targetDate = new Date("2024-01-13T00:00:00Z"); // 每秒更新倒數計時器 var countdown = setInterval(function() { var now = new Date().getTime(); // 取得目前時間 // 計算剩餘時間 var timeRemaining = targetDate - now; // 計算剩餘天數、小時、分鐘和秒數 var days = Math.floor(timeRemaining / (1000 * 60 * 60 * 24)); var hours = Math.floor((timeRemaining % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((timeRemaining % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((timeRemaining % (1000 * 60)) / 1000); // 將計算結果顯示在對應的元素中 document.getElementById("days").innerHTML = days; document.getElementById("hours").innerHTML = hours; document.getElementById("minutes").innerHTML = minutes; document.getElementById("seconds").innerHTML = seconds; // 如果倒數計時結束,停止更新計時器 if (timeRemaining < 0) { clearInterval(countdown); document.getElementById("countdown-container").innerHTML = "選舉已結束!"; } }, 1000);