execute a function at a certain time of day js

Solutions on MaxInterview for execute a function at a certain time of day js by the best coders in the world

showing results for - "execute a function at a certain time of day js"
Tim
02 Apr 2019
1window.setInterval(function(){ // Set interval for checking
2    var date = new Date(); // Create a Date object to find out what time it is
3    if(date.getHours() === 8 && date.getMinutes() === 0){ // Check the time
4        // Do stuff
5    }
6}, 60000); // Repeat every 60000 milliseconds (1 minute)
Matilda
07 Oct 2018
1setInterval(()=>{
2let now = new Date();
3//86400000 represents 10 hours in milliseconds Change it as you like
4if(now.getTime() == 86400000 ){
5  //your code
6}
7}, 1);
Alessio
10 Aug 2016
1var now = new Date();
2var millisTill10 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 10, 0, 0, 0) - now;
3if (millisTill10 < 0) {
4     millisTill10 += 86400000; // it's after 10am, try 10am tomorrow.
5}
6setTimeout(function(){alert("It's 10am!")}, millisTill10);