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.
Asked
Active
Viewed 1.5k times
5
-
show us more info's, what u have done so far ? – Ricardo Binns May 09 '12 at 12:51
-
for starters, you have [Date object](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) and [setInteval](https://developer.mozilla.org/en/DOM/window.setInterval) to check Date – Joseph May 09 '12 at 12:51
-
Will the JavaScript be persistent (i.e. server-side service / cron job) or transient (i.e. client-side web page)? – vansimke May 09 '12 at 12:52
-
Ah, I see you've edited your comment. Well, that makes mine useless, deleting. :) – Elliot Bonneville May 09 '12 at 12:57
-
@ElliotBonneville. Anyway I answred how it can be done (but shouldn't...) – gdoron May 09 '12 at 13:01
-
1@gdoron: Looks about right. +1 – Elliot Bonneville May 09 '12 at 13:05
2 Answers
12
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.
-
1
-
-
@George, I don't believe this is the case here as the OP didn't mention nodejs in his question text\tags\comments. – gdoron Sep 10 '13 at 16:32
-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();

Mojtaba Hoseinpour
- 527
- 6
- 19