deadlines

This commit is contained in:
2024-07-19 17:30:36 +02:00
parent 8a7ae9c2f9
commit 5858cee900
8 changed files with 182 additions and 50 deletions
+37
View File
@@ -0,0 +1,37 @@
let timer = null;
function startCountdown(dateString) {
if (timer) clearInterval(timer);
let cd = document.getElementById("countdown")
if (cd) {
cd.classList.remove("hide");
if (dateString == "None") cd.classList.add("hide");
}
const end = new Date(dateString).getTime();
const dayEl = document.getElementById('days');
const hoursEl = document.getElementById('hours');
const minutesEl = document.getElementById('minutes');
const secondsEl = document.getElementById('seconds');
const seconds = 1000;
const minutes = seconds * 60;
const hours = minutes * 60;
const days = hours * 24;
timer = setInterval(updateTime, seconds);
function updateTime() {
if (dayEl) {
let now = new Date().getTime();
const difference = end - now;
if (difference < 0) {
if (timer) clearInterval(timer);
cd.classList.add("hide");
return;
}
dayEl.innerText = Math.floor(difference / days);
hoursEl.innerText = Math.floor( (difference % days) / hours );
minutesEl.innerText = Math.floor( (difference % hours) / minutes );
secondsEl.innerText = Math.floor( (difference % minutes) / seconds );
}
}
updateTime();
}