带有时区的node-cron [英] node-cron with timezones

查看:81
本文介绍了带有时区的node-cron的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个节点(v0.7.3-pre)服务器,其中服务器带有

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);

它运行,但是Cron始终与服务器时间(UTC)配合使用,并且返回的cron为:

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:
...

区域被设置为 undefined ,我缺少什么吗?

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

推荐答案

因为node-cron模块中发生错误.我已经发送了一个拉动请求,它将对其进行修复.您可以在此模块的本地副本中更改此行.

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.

您还可以使用多个函数参数而不是一个对象来初始化cronJob:

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);

这篇关于带有时区的node-cron的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆