100-project-100-days-website/100_projects/80-simple-countdown-timer/main.js
2023-05-12 13:15:13 +03:00
Ask

22 lines
905 B
JavaScript

{499e6c45739717d01c840f95e3781237eeeec638 true 905 main.js 0xc002aa2fc0}

// 2023-5-13 || 1444-10-22
let countDownDate = new Date("Dec 31, 2025 23:59:59").getTime();
let counter = setInterval(() => {
let dateNow = new Date().getTime();
let dateDiff = countDownDate - dateNow;
let days = Math.floor(dateDiff / (1000 * 60 * 60 * 24));
let hours = Math.floor((dateDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
let minutes = Math.floor((dateDiff % (1000 * 60 * 60)) / (1000 * 60));
let seconds = Math.floor((dateDiff % (1000 * 60)) / 1000);
document.querySelector(".days").innerHTML = days < 10 ? `0${days}` : days;
document.querySelector(".hours").innerHTML = hours < 10 ? `0${hours}` : hours;
document.querySelector(".minutes").innerHTML = minutes < 10 ? `0${minutes}` : minutes;
document.querySelector(".seconds").innerHTML = seconds < 10 ? `0${seconds}` : seconds;
if (dateDiff < 0) {
clearInterval(counter);
}
}, 1000);