const interval = setInterval( () => {
let now = new Date();
let nowTime = now.getTime();
let days = Math.floor((startTime - nowTime) / DAY_IN_MS);
let hours = Math.floor((startTime - nowTime - days * DAY_IN_MS) / HOUR_IN_MS);
let minutes = Math.floor((startTime -
nowTime -
days * DAY_IN_MS -
hours * HOUR_IN_MS) /
MINUTE_IN_MS
);
let seconds = Math.floor(
(startTime -
nowTime -
days * DAY_IN_MS -
hours * HOUR_IN_MS -
minutes * MINUTE_IN_MS) /
SECOND_IN_MS
);
updateTimer(secondLeftUnite, secondRightUnite, seconds);
updateTimer(minuteLeftUnite, minuteRightUnite, minutes);
updateTimer(hourLeftUnite, hourRightUnite, hours);
}, 1000);
// define static variables outside of the setInterval as they won't change
let inputDate = new Date("2024-10-08");
const startTime = inputDate.getTime();
const SECOND_IN_MS = 1000;
const MINUTE_IN_MS = 60 * SECOND_IN_MS;
const HOUR_IN_MS = 60 * MINUTE_IN_MS;
const DAY_IN_MS = 24 * HOUR_IN_MS;
const interval = setInterval( () => {
let now = new Date();
let nowTime = now.getTime();
let days = Math.floor((startTime - nowTime) / DAY_IN_MS);
let hours = Math.floor((startTime - nowTime - days * DAY_IN_MS) / HOUR_IN_MS);
let minutes = Math.floor((startTime -
nowTime -
days * DAY_IN_MS -
hours * HOUR_IN_MS) /
MINUTE_IN_MS
);
let seconds = Math.floor(
(startTime -
nowTime -
days * DAY_IN_MS -
hours * HOUR_IN_MS -
minutes * MINUTE_IN_MS) /
SECOND_IN_MS
);
updateTimer(secondLeftUnite, secondRightUnite, seconds);
updateTimer(minuteLeftUnite, minuteRightUnite, minutes);
updateTimer(hourLeftUnite, hourRightUnite, hours);
}, 1000);
// define static variables outside of the setInterval as they won't change
let inputDate = new Date("2024-10-08");
const startTime = inputDate.getTime();
const SECOND_IN_MS = 1000;
const MINUTE_IN_MS = 60 * SECOND_IN_MS;
const HOUR_IN_MS = 60 * MINUTE_IN_MS;
const DAY_IN_MS = 24 * HOUR_IN_MS;