Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CronJob using timezone

Tags:

node.js

cron

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

like image 852
Umer Inayat Avatar asked Apr 30 '26 03:04

Umer Inayat


1 Answers

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

like image 143
Habeel Mazhar Avatar answered May 02 '26 17:05

Habeel Mazhar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!