I'm using CronJob in my NodeJs application. Everything works fine except I want to trigger CronJob according to specific timezone.
const membershipChangeCronJob = new CronJob({
cronTime: '0 5 12 * * *',
onTick: function () {
console.log('********************************************');
console.log('**********Membership Change Cron Job*************');
console.log('********************************************');
membershipeUpdate();
},
start: false
});
membershipChangeCronJob.start();
Is there anyway I can use moment timezone with CronJob? or is there any other workaround
Yes you can add a parameter or key of
timeZone
to add the required timezone
const membershipChangeCronJob = new CronJob({
cronTime: '0 5 12 * * *',
onTick: function () {
console.log('********************************************');
console.log('**********Membership Change Cron Job*************');
console.log('********************************************');
membershipeUpdate();
},
start: false,
timeZone: 'Asia/Singapore'
});
membershipChangeCronJob.start();
Documentation can be found here with examples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With