'Hangfire CRON in UTC time
I am trying to configure a recurring task in my MVC application starting at 00:00 every day. I know this can be achieved by RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Daily);.
Now my question is does hangfire cron work on basis of UTC time or the local time at server. If it works on local time, is there a way to run that on UTC time? I have to do this because this will be a day end process and all the scheduled tasks are scheduled based on the Universal time in my database.
Solution 1:[1]
To run in a specific timezone instead of UTC, look up the TimeZoneInfo you want. The task will run at midnight.
var manager = new RecurringJobManager();
manager.AddOrUpdate("some-id", Job.FromExpression(() => Method()),
Cron.Daily(),
TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));
Solution 2:[2]
RecurringJob.AddOrUpdate(() =>
homeCtrl.SendEmail(), Cron.Daily(),
TimeZoneInfo.Local);
// 12:00:00 AM
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nate Barbettini |
| Solution 2 | Syscall |
