Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

115
Vistas
Haga que el temporizador de cuenta regresiva vaya hasta las 9:30 a.m., luego a las 11 a.m. y luego reinicie al próximo domingo

Tengo el siguiente código, pero quiero ajustarlo para que podamos tener la cuenta regresiva para dos momentos diferentes.

 var secTime;
var ticker;

function getSeconds() {
 var nowDate = new Date();
 var dy = 1; //Sunday through Saturday, 0 to 6
 var countertime = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 21, 0, 0); //20 out of 24 hours = 8pm

 var curtime = nowDate.getTime(); //current time
 var atime = countertime.getTime(); //countdown time
 var diff = parseInt((atime - curtime) / 1000);
 if (diff > 0) {
 curday = dy - nowDate.getDay()
 } else {
 curday = dy - nowDate.getDay() - 1
 } //after countdown time
 if (curday < 0) {
 curday += 7;
 } //already after countdown time, switch to next week
 if (diff <= 0) {
 diff += (86400 * 7)
 }
 startTimer(diff);
}

function startTimer(secs) {
 secTime = parseInt(secs);
 ticker = setInterval("tick()", 1000);
 tick(); //initial count display
}

function tick() {
 var secs = secTime;
 if (secs > 0) {
 secTime--;
 } else {
 clearInterval(ticker);
 getSeconds(); //start over
 }

 var days = Math.floor(secs / 86400);
 secs %= 86400;
 var hours = Math.floor(secs / 3600);
 secs %= 3600;
 var mins = Math.floor(secs / 60);
 secs %= 60;

 //update the time display
 document.getElementById("days").innerHTML = curday;
 document.getElementById("hours").innerHTML = ((hours < 10) ? "0" : "") + hours;
 document.getElementById("minutes").innerHTML = ((mins < 10) ? "0" : "") + mins;
 document.getElementById("seconds").innerHTML = ((secs < 10) ? "0" : "") + secs;
}
 <body onload="getSeconds();">


 <h6>Live in <span class="days" id="days"></span><span class="smalltext"> days,</span>
 <span class="hours" id="hours"></span><span class="smalltext"> hours,</span>
 <span class="minutes" id="minutes"></span><span class="smalltext"> minutes</span>
 <span class="seconds" id="seconds"></span><span class="smalltext"> seconds</span>
 </h6>

</body>

Pero quiero que la cuenta regresiva llegue a las 9:30 a. m. y luego, tan pronto como llegue a las 9:30 a. m., comience la cuenta regresiva hasta las 11 a. m. Después de eso reinicia y pasa al siguiente domingo. ¿Cómo lograría esto?

almost 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

para simplificar, supondremos que está encendido un día de la semana. entonces solo necesitamos contar hasta la fecha objetivo1, luego la fecha objetivo2.

 var secTime;
var ticker;

var mode = "weekday"; // or "sunday" depending on a function yet to be written

function getSeconds() {
 var nowDate = new Date();
 var dy = 1; //Sunday through Saturday, 0 to 6
 if (mode == "weekday") {
 var countertime = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 09, 30, 00);
 }
 if (mode == "sunday") {
 var countertime = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 11, 00, 00);
 }

 if (mode == "sunday") {
 mode = "weekday"
 } else {
 mode = "sunday"
 }

 var curtime = nowDate.getTime(); //current time
 var atime = countertime.getTime(); //countdown time
 var diff = parseInt((atime - curtime) / 1000);
 if (diff > 0) {
 curday = dy - nowDate.getDay()
 } else {
 curday = dy - nowDate.getDay() - 1
 } //after countdown time
 if (curday < 0) {
 curday += 7;
 } //already after countdown time, switch to next week
 if (diff <= 0) {
 diff += (86400 * 7)
 }
 startTimer(diff);
}

function startTimer(secs) {
 secTime = parseInt(secs);
 ticker = setInterval(tick, 1000);
 tick(); //initial count display
}

function tick() {
 var secs = secTime;
 if (secs > 0) {
 secTime--;
 } else {
 clearInterval(ticker);
 getSeconds(); //start over
 }

 var days = Math.floor(secs / 86400);
 secs %= 86400;
 var hours = Math.floor(secs / 3600);
 secs %= 3600;
 var mins = Math.floor(secs / 60);
 secs %= 60;

 //update the time display
 document.getElementById("days").innerHTML = curday;
 document.getElementById("hours").innerHTML = ((hours < 10) ? "0" : "") + hours;
 document.getElementById("minutes").innerHTML = ((mins < 10) ? "0" : "") + mins;
 document.getElementById("seconds").innerHTML = ((secs < 10) ? "0" : "") + secs;
}
 <body onload="getSeconds();">


 <h6>Live in <span class="days" id="days"></span><span class="smalltext"> days,</span>
 <span class="hours" id="hours"></span><span class="smalltext"> hours,</span>
 <span class="minutes" id="minutes"></span><span class="smalltext"> minutes</span>
 <span class="seconds" id="seconds"></span><span class="smalltext"> seconds</span>
 </h6>

</body>

almost 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda