

Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!


Countdown al 4 novembre (solo giorni lavorativi)
Countdown al 4 novembre(solo giorni lavorativi)
--giorni lav. --ore --min --sec
const daysEl = document.getElementById("days"); const hoursEl = document.getElementById("hours"); const minutesEl = document.getElementById("minutes"); const secondsEl = document.getElementById("seconds"); const msgEl = document.getElementById("message"); // Funzione per contare i giorni lavorativi tra due date function workingDaysBetween(start, end) { let count = 0 ; let cur = new Date(start); cur.setHours( 0 , 0 , 0 , 0 ); end = new Date(end); end.setHours( 0 , 0 , 0 , 0 ); while (cur < end) { const day = cur.getDay(); // 0 =dom, 6 =sab if (day !== 0 && day !== 6 ) count++; cur.setDate(cur.getDate() + 1 ); } return count; } function getTarget(now){ let year = now.getFullYear(); let t = new Date(year, TARGET_MONTH, TARGET_DAY, 0 , 0 , 0 ); if (now >= t) t = new Date(year+ 1 , TARGET_MONTH, TARGET_DAY, 0 , 0 , 0 ); return t; } function update(){ const now = new Date(); const target = getTarget(now); const diffMs = target - now; if (diffMs <= 0 ){ daysEl.textContent = " 00 "; hoursEl.textContent = " 00 "; minutesEl.textContent = " 00 "; secondsEl.textContent = " 00 "; msgEl.textContent = "È arrivato il 4 novembre! "; return; } // Giorni lavorativi rimanenti const workDays = workingDaysBetween(now, target); daysEl.textContent = String(workDays).padStart( 2 ," 0 "); // Ore, minuti, secondi rimanenti nel tempo reale