Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!