【问题标题】:I want to schedule a task at specific time with timezone specified with using node-scheduler, How should I do it?我想在特定时间安排使用节点调度程序指定时区的任务,我应该怎么做?
【发布时间】:2020-09-09 16:51:16
【问题描述】:

以上是我的代码,我想将其用作通知调度程序,但无法正常工作

  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)

【问题讨论】:

    标签: node.js cron scheduler node-cron node-schedule


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-11-30
      • 2018-12-11
      • 1970-01-01
      • 2023-02-21
      • 2013-06-03
      • 2011-08-12
      • 1970-01-01
      • 2011-06-21
      • 2014-10-28
      相关资源
      最近更新 更多