const deadline = '2020-11-10';
function getTimeRemaining(endtime) {
const t = Date.parse(endtime) - Date.parse(new Date()),
days = Math.floor(t / (1000 * 60 * 60 * 24)),
hours = Math.floor((t / (1000* 60 * 60) % 24)),
minutes = Math.floor((t / 1000 / 60) % 60),
seconsd = Math.floor((t / 1000) % 60);
return {
'total': t,
'days': days,
'hours': hours,
'minutes': minutes,
'seconsd': seconsd
};
}
function getZero(num) {
if(num >= 0 && num < 10) {
return `0${num}`;
} else {
return num;
}
}
function setClock(selector, endtime) {
const timer = document.querySelector(selector),
days = timer.querySelector('#days'),
hours = timer.querySelector('#hours'),
minutes = timer.querySelector('#minutes'),
seconsd = timer.querySelector('#seconsd'),
timeInterval = setInterval(updateClock, 1000);
updateClock();
function updateClock() {
const t = getTimeRemaining(endtime);
days.innerHTML = getZero(t.days);
hours.innerHTML = getZero(t.hours);
minutes.innerHTML = getZero(t.minutes);
seconsd.innerHTML = getZero(t.seconsd);
if (t.total <= 0) {
clearInterval(timeInterval);
}
}
}
setClock('.timer', deadline);
Добавить комментарий
|
1 ответ
t.seconsd
- это так и задумывалось? :)
причем по всему коду - CopyPaste - это зло