Ejemplo 1: cuenta regresiva de la fecha de JavaScript
<!--Display the countdown timer in an element --><p id="demo"></p><script>// Set the date we're counting down tovar countDownDate =newDate("Jan 5, 2021 15:37:25").getTime();// Update the count down every 1 secondvar x =setInterval(function()// Get today's date and timevar now =newDate().getTime();// Find the distance between now and the count down datevar distance = countDownDate - now;// Time calculations for days, hours, minutes and secondsvar 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);// Display the result in the element with id="demo"document.getElementById("demo").innerHTML= days +"d "+ hours +"h "+ minutes +"m "+ seconds +"s ";// If the count down is finished, write some textif(distance <0)clearInterval(x);document.getElementById("demo").innerHTML="EXPIRED";,1000);</script>
Ejemplo 2: temporizador de cuenta atrás de JavaScript que incluye días
var countDownDate =newDate("Jul 25, 2021 16:37:52").getTime();var myfunc =setInterval(function()var now =newDate().getTime();var timeleft = countDownDate - now;var days =Math.floor(timeleft /(1000*60*60*24));var hours =Math.floor((timeleft %(1000*60*60*24))/(1000*60*60));var minutes =Math.floor((timeleft %(1000*60*60))/(1000*60));var seconds =Math.floor((timeleft %(1000*60))/1000);,1000)
Comentarios y calificaciones de la guía
Recuerda que puedes optar por la opción de decir si te fue de ayuda.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)