Time zone problem with HF in Azure


I have an odd problem using Hangfire within my web app on Azure which runs generally in UTC Timezone.

I create scheduled and recurring jobs from within my app. My problem at the moment is that the time within my web app and the internal time of Hangfire (in the footer of the Dashboard) seems to be different. Hangfire runs inside my app and so on the same machine.

Web App (Azure) => DateTime.now => 8/21/2018 10:04:16 PM
Hangfire Time shown in the Footer of Dashboard => 8/22/2018 12:04:46 AM (this is my local time)

So Hangfire seems to be 2 hours ahead or shows MY correct time zone time here in Germany.

The strange thing is that the recurring job seems to be scheduled correctly, related to the Azure Time

9cca7f2e-f042-4c96-9be7-107e115b3030 7 0 * * * UTC TwitterPostJobs.DoTwitterPost in 2 hours

This leads to the problem that the cron schedule is correct but not the execution time of the job. Because it IS 00:04 now, so the job normally needs to be executed in 3 minutes and not in 2 hours.

Have you tried to schedule based on DateTime.UtcNow ?
Also, you can specify the timezone when scheduling. Ex:

TimeZoneInfo timeZone;
	timeZone = TimeZoneInfo.FindSystemTimeZoneById("E. South America Standard Time");
	timeZone = TimeZoneInfo.CreateCustomTimeZone("BRST", TimeSpan.FromHours(-3), "(UTC-03:00) Brasília", "Hora oficial do Brasil");
RecurringJob.AddOrUpdate("YourJobName", () => DoSomeWork, "your cron expression", timeZone);

Hope it helps… :wink: