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

121
Vistas
Sending alert at certain time using javacript

I've success set single time to send alert. But I have problem to set multiple time. How set multiple time to send alert? Example: I have to send alert at 14:05, 17: 35 and 19:12

<script type="text/javascript">
var alarmDate = new Date();
alarmDate.setHours(21);
alarmDate.setMinutes(47);
// set day, month, year, etc.



function setAlarm(){
    var currentDate = new Date();

    if (currentDate.getHours() == alarmDate.getHours() &&
             currentDate.getMinutes() == alarmDate.getMinutes() 
      /* compare other fields at your convenience */ ) {
        alert('Alarm triggered at ' + currentDate);
        // better use something better than alert for that?

    }
}

setInterval(setAlarm,1000)
</script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use setTimeout instead. There is no reason to call a piece of code to cehck what time it is every single second. Just wait until the time when you want to execute something.

// Set your alarm date to whatever you require

var alarmDate = new Date();
alarmDate.setSeconds(alarmDate.getSeconds() + 5);

setAlarm(alarmDate, function(){
  alert('Alarm triggered at ' + new Date());
});

var alarmDate2 = new Date();
alarmDate2.setSeconds(alarmDate2.getSeconds() + 10);

setAlarm(alarmDate2, function(){
  alert('Alarm triggered at ' + new Date());
});

function setAlarm(date, callback){
  // How much time from now until the alarmDate
  var timeUntilAlarm = date - new Date();

  // Wait until the alarm date, then do stuff.
  setTimeout(callback, timeUntilAlarm);
}

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