最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Running cron job at only specific date and time - Stack Overflow

programmeradmin1浏览0评论

In our express js application have a feature in admin module that he can send mail to users at specific dates (he can able to select a specific date and time).

Say if the date and time is [email protected] we need to run the email code at that time.

I think this package will full fill our needs ,

Here is their documentation

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    │
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)

But it doesn't say how to run on specific date (year field is missing??) so how do i achieve my need?

In our express js application have a feature in admin module that he can send mail to users at specific dates (he can able to select a specific date and time).

Say if the date and time is [email protected] we need to run the email code at that time.

I think this package will full fill our needs https://www.npmjs./package/node-schedule,

Here is their documentation

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    │
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)

But it doesn't say how to run on specific date (year field is missing??) so how do i achieve my need?

Share Improve this question asked Jan 16, 2018 at 4:55 shamon shamsudeenshamon shamsudeen 5,85820 gold badges74 silver badges144 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

for specific date, you could use something like following as provided in example

var schedule = require('node-schedule');
var date = new Date(2018, 1, 22, 12, 0, 0);

var j = schedule.scheduleJob(date, function(){
  console.log('job is running');
});

You can pass date object in it. if you read document further you will find it here : https://www.npmjs./package/node-schedule#date-based-scheduling

var schedule = require('node-schedule');
var date = new Date(2012, 11, 21, 5, 30, 0);

var j = schedule.scheduleJob(date, function(){
 console.log('The world is going to end today.');
});
发布评论

评论列表(0)

  1. 暂无评论