Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MoisesTedeschi/34359f4ccd81f1e47da5b8ec7d3ac22c to your computer and use it in GitHub Desktop.
Save MoisesTedeschi/34359f4ccd81f1e47da5b8ec7d3ac22c to your computer and use it in GitHub Desktop.
Contador zerando quando chega na data limite.
<div class="contagem">
Faltam apenas
<mark><span class="numero" id="days"></span> DIAS, <span id="hours"></span> HORAS,
<span class="numero" id="minutes"></span> MINUTOS</mark> E <mark><span class="numero" id="seconds"></span> SEGUNDOS</mark>
</div>
<script>
var countDownDate = new Date("Aug 02, 2021 20:00:00").getTime();
var countdown = setInterval(function() {
var now = new Date().getTime();
var difference = countDownDate - now;
var days = Math.floor(difference / (1000 * 60 * 60 * 24));
var hours = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((difference % (1000 * 60)) / 1000);
if (difference < 0) {
clearInterval(countdown);
days = 0, hours = 0, minutes = 0, seconds = 0;
}
document.getElementById("days").innerText = days;
document.getElementById("hours").innerText = hours;
document.getElementById("minutes").innerText = minutes;
document.getElementById("seconds").innerText = seconds;
}, 1000);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment