I'm doing a "countdown" timer that counts the time it takes to get to a certain date (in the case November 30). I pass this information on; days, hours, minutes, and seconds.
The case is that I wanted to display the tenths of seconds.
var countDownDate = new Date("Nov 30, 2018 00:00:00").getTime();
var x = setInterval(function() {
var now = new Date().getTime();
var distance = countDownDate - now;
//calculation getElementById("")
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
//fazer o calculo de décimos
document.getElementById("days").innerHTML = days + "<br><small>dias</small>";
document.getElementById("hours").innerHTML = hours + "<br><small>horas</small>";
document.getElementById("minutes").innerHTML = minutes + "<br><small>minutos</small>";
document.getElementById("seconds").innerHTML = seconds + "<br><small>segundos</small>";
}, 1000);
.clock .clock-box {
display: inline-block;
text-align: center;
margin: 5px;
}
.clock-box {
background-color: black;
color: lightgreen;
border-radius: 5px;
width: 60px;
font-size: 10px;
}
<div class="clock">
<div class="clock-box" id="days"></div>
<div class="clock-box" id="hours"></div>
<div class="clock-box" id="minutes"></div>
<div class="clock-box" id="seconds"></div>
<div class="clock-box" id="dSeconds"></div>
</div>
In case I would have to divide by 1010 instead of 1000? In addition to the calculation, will I need to change the set time out?