0

I use node-cron library for working with schedule task. I want to run my task every 1hr ( 00.00, 01.00, 02.00...24.00) in timezone of UTC but it doesn't work ( time was incorrect)

Thank you.

Nawin Poolsawad
  • 227
  • 2
  • 13

2 Answers2

1

From the docs:

See IANA time zone database for valid values, such as Asia/Shanghai, Asia/Kolkata, America/Sao_Paulo.

You can see list of tz database time zones at wikipedia.

let task24 = cron.schedule('0 * * * *' async () => {
    // task
}, { timezone: 'Etc/UTC' })

Update

There's a memory leak bug if you set the node-cron's options.timezone. Unless the issue is fixed, use croner instead. Here's how to migrate from node-cron to croner.

M Imam Pratama
  • 998
  • 11
  • 26
0

You need to define the time you want. You can use this website to do this.

Or use this example :

var cron = require('node-cron');

cron.schedule("0 * * * *", () => { // 0 * * * * = every houre at minute 0
    console.log("running a task every houre");
});
mvetois
  • 111
  • 11