我想使用节点调度程序指定的时区在特定时间安排任务,我应该怎么做?



以上是我的代码,我想将其用作通知调度程序,但不起作用

const nodeSchedule = require('node-schedule');
var a = new Date();
let rule2 = new nodeSchedule.RecurrenceRule();
rule2.second = a.getSeconds();
rule2.minute = a.getMinutes() + 2;
rule2.hour = a.getHours();
rule2.year = a.getFullYear();
rule2.month = a.getMonth() + 1; // beware: January = 0; February = 1, etc.
rule2.date = a.getDate();
rule2.tz = 'America/Araguaina';
var job = nodeSchedule.scheduleJob('demo', rule2, function () {
console.log('worked..');
});
console.log(job)

我建议你使用 cron 而不是 node-schedule。 它为您提供了更多的控制权。

1.您可以在不更改代码的情况下更改cron时间(SetTime( 2.你有很多方法可以用于这个库,比如fireOnTick addCallback等。 3.可以动态启动和停止作业。 4.您可以访问onTick和onComplete功能 https://www.npmjs.com/package/cron 5.您可以轻松设置时区。

最新更新