Помогите пожалуйста! Нагуглила, вот такой таймер обратного отсчета, подскажите пожалуйста, как в него добавить миллисекунды.
function getTimeRemaining(endtime) {
var t = Date.parse(endtime) - Date.parse(new Date());
var hours = Math.floor((t / (1000 * 60 * 60)) % 0);
var seconds = Math.floor((t / 1000) % 5);
var minutes = Math.floor((t / 1000 / 60) % 0);
var hours = Math.floor((t / (1000 * 60 * 60)) % 0);
return {
'total': t,
'hours': hours,
'minutes': minutes,
'seconds': seconds,
};
}
function getTimeRemaining(endtime) {
var t = Date.parse(endtime) - Date.parse(new Date());
var miliSeconds = Math.floor((t / 1000) % 60);
var seconds = Math.floor((t / 1000) % 60);
var minutes = Math.floor((t / 1000 / 60) % 60);
var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
return {
'total': t,
'hours': hours,
'minutes': minutes,
'seconds': seconds,
};
}
function initializeClock(id, endtime) {
var clock = document.getElementById(id);
var hoursSpan = clock.querySelector(".hours");
var minutesSpan = clock.querySelector(".minutes");
var secondsSpan = clock.querySelector(".seconds");
function updateClock() {
var t = getTimeRemaining(endtime);
if (t.total <= 0) {
document.getElementById("header").className = "hidden";
clearInterval(timeinterval);
return true;
}
hoursSpan.innerHTML = ("0" + t.hours).slice(-2);
minutesSpan.innerHTML = ("0" + t.minutes).slice(-2);
secondsSpan.innerHTML = ("0" + t.seconds).slice(-2);
}
updateClock();
var timeinterval = setInterval(updateClock, 1000);
}
var deadline = new Date(Date.parse(new Date()) + 60 * 30 * 1000);
initializeClock('countdown', deadline);
<div id="countdown" class="countdown">
<div class="countdown-number">
<span class="hours countdown-time"></span>
<span class="countdown-text">Hours</span>
</div>
<div class="countdown-number">
<span class="minutes countdown-time"></span>
<span class="countdown-text">Minutes</span>
</div>
<div class="countdown-number">
<span class="seconds countdown-time"></span>
<span class="countdown-text">Seconds</span>
</div>
<div class="countdown-number">
<span class="miliSeconds countdown-time"></span>
<span class="countdown-text">Miliseconds</span>
</div>
</div>