0

I am running a cron job every hour but it is not working as expected. It should run every hour on the hour, for example 1pm, 2pm, 3pm and so on.
But it is running 30 minutes late. 1:30pm, 2:30pm and so on...

I am using node-cron in Node.js and server is Digital Ocean Ubuntu.

Here is the code

var moment = require('moment');
var cron = require('node-cron');
cron.schedule('0 * * * *', function () {
    console.log('cron job started at ' + moment().utcOffset(330).format());
});

Output -Its running delay of 30 minutes
cron job started at 2018-02-10T17:30:00+05:30
cron job started at 2018-02-10T18:30:00+05:30
cron job started at 2018-02-10T19:30:00+05:30
cron job started at 2018-02-10T20:30:00+05:30

I want output as- at every hour start

cron job started at 2018-02-10T17:00:00+05:30
cron job started at 2018-02-10T18:00:00+05:30
cron job started at 2018-02-10T19:00:00+05:30
cron job started at 2018-02-10T20:00:00+05:30

Oliver
  • 11,857
  • 2
  • 36
  • 42
Gaurav Umrani
  • 124
  • 4
  • 12

1 Answers1

1

You're changing the timezone of what moment() returns by adding 3.5h by calling .utcOffset(330).
Remove the call to utcOffset() and it should show the correct time.

Oliver
  • 11,857
  • 2
  • 36
  • 42