Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default time zone in azure website service?

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?

like image 375
Kim-Jimin Avatar asked Oct 10 '12 06:10

Kim-Jimin


People also ask

What time zone are Azure servers in?

By default, on Azure App Service, the time zone is always UTC, but you can change it.

How do I change my Azure Web app location?

You cannot change the location of an app service plan, regardless of subscription type. You simply need to create a new app service plan in the region you want, and then redeploy your code.

Does Azure use UTC time?

By default, all Azure DevOps organizations and user accounts are set to UTC (Coordinated Universal Time) irrespective of what zones they are hosted in. Even if your organization migrated from an on-premises server to Azure DevOps Services, your timezone is set to UTC time.


2 Answers

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".

like image 173
Tom Hollander Avatar answered Oct 10 '22 18:10

Tom Hollander


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);
like image 31
Petr Abdulin Avatar answered Oct 10 '22 18:10

Petr Abdulin