'Creating Scheduled Task in JavaScript
I am creating an application in javascript which send notification on every sunday 12.00 am.
What should I do to call a function on that time.
Solution 1:[1]
I wouldn't do it with javascript
That said(with shouting...)
function foo(){
var day =new Date().getDay();
var hours =new Date().getHours();
if (day === 0 && hours >12 && hours < 13) // day is a 0 index base
// sunday between 12:00 and 13:00
// Do what you want here:
}
setInterval(foo, 3600000); // one hour check.
Solution 2:[2]
another solution is 3rd parties like: cron
var CronJob = require('cron').CronJob;
var job = new CronJob('0 0 0 * * 0', function() {
console.log('You will see this message every sunday, 12 am');
}, null, true, 'America/Los_Angeles');
job.start();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
| Solution 2 | Mojtaba Hoseinpour |
