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

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

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 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!