Answers for "code that will execute at a certain day and time javascript"

0

execute a function at a certain time of day js

window.setInterval(function(){ // Set interval for checking
    var date = new Date(); // Create a Date object to find out what time it is
    if(date.getHours() === 8 && date.getMinutes() === 0){ // Check the time
        // Do stuff
    }
}, 60000); // Repeat every 60000 milliseconds (1 minute)
Posted by: Guest on August-09-2021
0

code that will execute at a certain day and time javascript

var now = new Date();
var millisTill10 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 10, 0, 0, 0) - now;
if (millisTill10 < 0) {
     millisTill10 += 86400000; // it's after 10am, try 10am tomorrow.
}
setTimeout(function(){alert("It's 10am!")}, millisTill10);
Posted by: Guest on August-09-2021

Code answers related to "code that will execute at a certain day and time javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language