We've got a webjob that runs on .Net Framework 4.7.1 and that performs a datetime conversion from DateTimeOffset.UtcNow
to Chile continental time (that is if I'm not mistaken "Pacific SA Standard Time").
When running this webjob locally (in a Windows 10 machine) it works correctly and performs the conversion applying the DST, but when deployed to an Azure App Service this doesn't work anymore, and the final DateTime is always one hour later than the current official time.
I initially switched from TimeZoneInfo.ConvertTimeBySystemTimeZoneId
to TimeZoneInfo.ConvertTimeFromUtc
under the assumption that the first doesn't consider DST but that didn't work;
then I've tried switching "wrong" my own PC, changing my timezone to 'UTC_dstoff' and disabling in the 'Adjust date/time' menu the options 'Adjust for daylight saving time automatically' and also 'Set time automatically' but it still works as expected locally;
last thing I've tried was to change the timezone to the App Service using the environment variable WEBSITE_TIME_ZONE
to 'Pacific SA Standard Time' and it wasn't conclussive. I would say it initially seemed to have worked but after some more changes of timezone it starting adding one hour again.
This can be reproduced with the following lines:
var timeZoneId = "Pacific SA Standard Time";
var timeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
var dateTimeOffset = DateTimeOffset.UtcNow;
var localTime = TimeZoneInfo.ConvertTimeFromUtc(dateTimeOffset.DateTime, timeZone);
I would expect the function TimeZoneInfo.ConvertTimeFromUtc
would correctly apply DST when a timezone with DST is selected both locally and in the Azure App Service. Instead, it seems to work properly in Windows 10 but randomly in Azure App Service.