node-cron with timezones

杀马特。学长 韩版系。学妹 提交于 2021-01-22 10:35:43

问题


i have a node(v0.7.3-pre) server with node-cron(0.3.2) and node-time(0.8.2):

var cronJob = require('cron').CronJob;
var cronJ = new cronJob({
 cronTime: "00 29 16 6 * *",
 onTick: function() {
  console.log("Tick");
 },
 start:true,
 timeZone: "America/Los_Angeles"
});
console.log(cronJ);

it runs, but the Cron is allways working with the server time(UTC), and the returned cron is:

{ _callbacks: [ [Function] ],
  onComplete: undefined,
  cronTime:
   { source: '00 29 16 6 * *',
     zone: undefined,
     second: { '0': true },
     minute: { '29': true },
     hour: { '16': true },
     dayOfWeek:
...

the zone is set as undefined, am i missing something?


回答1:


Because an error in node-cron module. I already send a pull request that will fix it. You can change this lines in your local copy of this module.

You also can use several function parameters to initialize cronJob instead of one object:

var cronJob = require('cron').CronJob;
var cronJ = new cronJob("00 29 16 6 * *", function() {
        console.log("Tick");
}, undefined, true, "America/Los_Angeles");

console.log(cronJ);


来源:https://stackoverflow.com/questions/10918541/node-cron-with-timezones

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!