Привет, есть код :
const deadline = '2021-02-20';
function getTimeRemaining (endtime) {
const t = Date.parse(endtime) - Date.parse(new Date());
const days = Math.floor(t / (1000 * 60 * 60 * 24));
const hours = Math.floor((t/(1000 * 60 * 60) % 24));
const minutes = Math.floor((t/(1000 * 60) % 60));
const seconds = Math.floor((t/1000) % 60);
return {
'total': t,
'day': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
}
}
function setClock (selector, endtime) {
const timer = document.querySelector(selector);
const days = timer.querySelector('#days');
const hours = timer.querySelector('#hours');
const minutes = timer.querySelector('#minutes');
const seconds = timer.querySelector('#seconds');
const timeInterval = setInterval(updateClock, 1000);
function updateClock () {
const t = getTimeRemaining (endtime);
days.innerHTML =
t.day;
hours.innerHTML = t.hours;
minutes.innerHTML = t.minutes;
seconds.innerHTML = t.seconds;
if (
t.total <= 0) {
clearInterval(timeInterval);
}
}
}
setClock('.timer', deadline)