19

I'm new to Azure Web Sites service. I uploaded my web site files and it works very nice.

But I have a problem with default time zone. My location is Seoul(+9). But the code return UTC(+0) time when I call below.

DateTime.Now;

Is there any way to solve this problem without complicated fix like editing Web.config?

Kim-Jimin
  • 674
  • 2
  • 9
  • 19

2 Answers2

48

It is now possible to change the server time zone for your Azure Websites / Web Apps.

To do this, add an application setting (using the portal) called “WEBSITE_TIME_ZONE” equal to the name of the time zone in question (basically the same string as the key name at HKLM\Software\Microsoft\Windows Nt\CurrentVersion\Time Zones\).

The list of time zone values is here. Use a value from the column labeled "Name of Time Zone".

Rich Wagenknecht
  • 712
  • 7
  • 16
Tom Hollander
  • 673
  • 6
  • 6
  • Top marks for a solution which doesn't require code changes. Thanks! – cuzzlor Apr 15 '15 at 03:43
  • Unfortunate this will not work for databases on Azure. GetDate() in mssql azure database still returns UTC with this setting. – MFasseur May 15 '15 at 08:52
  • 2
    True, but the question is about Web Apps. – Tom Hollander May 17 '15 at 08:27
  • **WARNING**, as of today (25 May, 2015) this setting does **NOT** work properly. See this diagnostics output that was taken at 9:33 AM UTC http://i.stack.imgur.com/9WyvQ.png after "changing" timezone to EST using this setting. – Eugene D. Gubenkov May 25 '15 at 20:43
  • source: http://blogs.msdn.com/b/waws/archive/2014/08/05/get-the-local-server-time-for-your-azure-web-site.aspx – PussInBoots Jun 12 '15 at 20:55
  • 6
    Just changed it in my webapps app settings and works fine. For me, UK time is WEBSITE_TIME_ZONE = GMT Standard Time – David Aleu Oct 09 '15 at 10:13
  • @EugeneD.Gubenkov What exact value did you put in your application setting? – Anders Marzi Tornblad Feb 01 '16 at 12:32
  • Where did you find it ?? that WEBSITE_TIME_ZONE – monstro Mar 11 '16 at 15:36
  • This works for the most part but does not take daylight savings time into consideration. – stephen Mar 31 '16 at 20:09
  • I'm struggling to get this to work for British Summer Time. The code seems to ignore a setting with the value "Greenwich Summer Time" or "British Summer Time". If I change it to something like "Easter Standard Time" it does work, so is it possible that there are some timezone settings that are not supported? – Adam Diament Sep 06 '16 at 12:16
  • 3
    You don't need to explicitly ask for a daylight savings time zone. The DST adjustment will happen automatically if you specify the correct standard time zone. – Tom Hollander Sep 07 '16 at 21:56
  • "US Eastern Standard Time" for US Eastern with automatic DST – Kirill Yunussov Nov 29 '16 at 21:51
  • To get this setting to work for Australian Eastern Standard Time I had to use the value "AUS Eastern Standard Time" instead of the "A.U.S. Eastern Standard Time" recommended in the linked time zone page. I discovered this in the registry. I suspect timezones have been renamed in later versions of Windows. – Mark Glasgow May 02 '20 at 22:39
13

Changing TimeZone on Azure VMs is not recommended according to Microsoft. Instead convert time to local using methods of TimeZoneInfo structure.

However at least one possible solution is mentioned in the above mentioned post.

P.S. an example of solution provided by question author in comment below:

DateTime timeUtc = DateTime.UtcNow;
TimeZoneInfo kstZone = TimeZoneInfo.FindSystemTimeZoneById("Korea Standard Time"); 
DateTime kstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, kstZone);
Community
  • 1
  • 1
Petr Abdulin
  • 33,883
  • 9
  • 62
  • 96
  • DateTime timeUtc = DateTime.UtcNow; TimeZoneInfo kstZone = TimeZoneInfo.FindSystemTimeZoneById("Korea Standard Time"); DateTime kstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, kstZone); – Kim-Jimin Oct 10 '12 at 07:27