Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# DateTime.Now in Azure not reporting GMT - can the default timezone be set?

In azure websites the DateTime.Now always gives back the time in UTC, where I need to be able to set the timezone to GMT, so all times are currently an hour out.

I'm not able to change any of the code at this point, so the question is whether the default timezone can be changed either in configuration or programatically (it's possible to set the default culture in Global.asax to ensure date formats are correct).

like image 544
Paul Avatar asked May 27 '15 10:05

Paul


1 Answers

First, GMT is essentially the same as UTC - it has no offset. To be precise, UTC supersedes GMT . You are probably confusing it with BST which is GMT+1:00 during summer time.

In general, it's a bad idea to make assumptions about timezones, especially in web applications. Instead of DateTime you should use DateTimeOffset.

Luckily, there was a recent change for Azure Web Sites and now you can change the timezone of an Azure Web site in a supported and reliable way. From the MSDN blog post

All you need to do is add an Application Setting (via the portal or the management APIs) called WEBSITE_TIME_ZONE and set that to the name of the time zone as defined in the Windows Registry under HKLM\Software\Microsoft\Windows Nt\CurrentVersion\Time Zones\ (for example, “AUS Eastern Standard Time”).

Unfortunately, Windows mixes up the timezones and uses the name "GMT Standard Time" to refer to BST and "UTC" to refer to GMT/UTC.

like image 168
Panagiotis Kanavos Avatar answered Oct 19 '22 07:10

Panagiotis Kanavos