Reputation: 390
Does anyone know the default timezone used by Hangfire when setting up a recurring job? I suspect it is UTC and not the timezone of the host server.
Upvotes: 1
Views: 5599
Reputation: 131219
I suspect the real question is how to specify the timezone, not whether it's UTC or local.
The Cron class docs explicitly specify that UTC is used, eg:
Daily() Returns cron expression that fires every day at 00:00 UTC.
Daily(Int32) Returns cron expression that fires every day at the first minute of the specified hour in UTC.
etc
That's just the default though. The Cron
class doesn't hard-code the timezone, it simply creates a CRON string. If you want to use a different timezone you can pass it through the timeZone
parameter in all AddOrUpdate overloads.
The parameter accepts a TimeZoneInfo instance. TimeZoneInfo allows you to specify a timezone by its Windows name, UTC or Local
, in which case it returns the system's timezone.
In that case though the problem becomes What's the server's timezone?
If the web app needs to use a specific timezone it's better to be explicit, especially when using cloud VMs
Upvotes: 6