generated from egmont11/ASP.Net-Core-MVC-Template
23 lines
798 B
JavaScript
23 lines
798 B
JavaScript
const PARTY_DATE = new Date(2026, 9, 23, 18, 0);
|
|
|
|
function updateTimer() {
|
|
const timerEl = document.getElementById("timer");
|
|
const diff = PARTY_DATE - new Date();
|
|
|
|
if (diff <= 0) {
|
|
timerEl.textContent = "Večírek již začal!";
|
|
clearInterval(intervalId);
|
|
return;
|
|
}
|
|
|
|
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
|
const hours = Math.floor(diff / (1000 * 60 * 60)) % 24;
|
|
const minutes = Math.floor(diff / (1000 * 60)) % 60;
|
|
const seconds = Math.floor(diff / 1000) % 60;
|
|
|
|
timerEl.textContent =
|
|
`${days} dní a ${String(hours)}:${String(minutes)}:${String(seconds).padStart(2, "0")}`;
|
|
}
|
|
|
|
updateTimer(); // run immediately so the span isn't empty for the first second
|
|
const intervalId = setInterval(updateTimer, 1000); |