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.
// If you want to run it at a specific time it can be like this:
// It will run every day at 10:36:00 AM
const cron = require('node-cron');
cron.schedule('00 36 10 * * *', () => {
console.log(new Date());
});
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' })
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
.
You need to define the time you want. You can use this website to do this.
Or use this example :