2
I’m making a "Countdown" stopwatch that counts the time remaining to get to a certain date (in case 30 November). I pass this information on; days, hours, minutes and seconds.
The thing is, I wanted to show off 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? Besides the calculation, I will need to change the set time out?
Silly curiosity... I read and reread your post, I did not understand how you arrived at this value "1010", I must have distracted in some detail. I could explain?
– Bacco
pq javascript picks the date by thousandth of a second, then I thought that would get the tenth kkkkkkkk but it didn’t roll, I tested here kkkkk a number nothing to see
– MSHijo
Mshijo still not understand right, but thanks for the return :D
– Bacco
really the recoveries I picked up in math at school make sense kkkkkkk
– MSHijo