1
I need a regressive counter but as my acquaintances are still more timid in js
, in that code I don’t know how to add "0" in the fields hour, minutes and seconds.
As it is returns me only full numbers (ex.: 0 : 1 : 7). In math.floor
as I add more decimal places?
Code:
// Set the date we're counting down to
var countDownDate = new Date("Mar 21, 2017 16:35:00").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
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);
// Output the result in an element with id="demo"
document.getElementById("cont").innerHTML = days + " dias " + hours + " : "
+ minutes + " : " + seconds;
// Output the result in an element with id="demo2"
document.getElementById("cont2").innerHTML = " HRS " + " MIN " + " SEG ";
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("cont").innerHTML = "TEMPO EXPIRADA";
}
}, 1000);
#cont {
text-align: center;
font-size: 25px;
font-family: "Oswald", Arial, sans-serif;
}
#cont2 {
text-align: center;
font-size: 15px;
font-family: "Oswald", Arial, sans-serif;
}
<p id="cont"></p>
<p id="cont2"></p>
Sorry to intrude on the code, but I removed the element
p1
that you created and added css toid
s of the elements– Erlon Charles
I modified the answer by inserting the time the time expired.
– Erlon Charles