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

157
Views
Activar javascript del lado del cliente según la fecha y hora

Tengo una hora de inicio de evento y quiero ejecutar una secuencia de comandos 10 segundos después de que comience el evento, pero no sé cómo activar la secuencia de comandos.

 const date = Date().toString(); const currentDateParse = Date.parse(date); const trigger = Date.parse(startTime) + 1000 * 10

Entonces así es como intento activar el script pero no funciona. ¿Cómo inicio mi función cuando currentDateParse es igual a trigger ? O, en pocas palabras, 10 segundos después de que comience el evento.

 if (currentDateParse = trigger) <function code underneath works already>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Calcule la diferencia de tiempo entre ahora y cuando desea activar el script, y use setTimeout() para llamarlo en ese momento.

 const timediff = trigger - new Date().getTime(); setTimeout(function() { // do what you want }, timediff);
about 4 years ago · Juan Pablo Isaza Report

0

Pruebe esto (explicaciones a continuación):

 let startTime = "18:00"; let currentTime = new Date(); let target = new Date().parse(startTime); let timeout = target - currentTime + 1000 * 10; // how long should it wait till the functions is executed function runTenSecAfterEvent() { // do something here } setTimeout(runTenSecAfterEvent, timeout);

Explicaciones

Después de calcular target (la hora de inicio) y el tiempo currentTime , necesita saber la diferencia de tiempo entre ellos (tiempo de timeout ), por lo tanto, target menos tiempo currentTime . Después de eso, agregas los 10000ms .

Y luego define la función que se ejecutará 10 segundos después de que ocurra el evento ( runTenSecAfterEvent() ).

Finalmente, crea un tiempo de espera .

about 4 years ago · Juan Pablo Isaza 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!