How to change default time zone in azure website service?

三世轮回 提交于 2019-11-29 00:57:10

问题


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?


回答1:


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\).




回答2:


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);


来源:https://stackoverflow.com/questions/12813123/how-to-change-default-time-zone-in-azure-website-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!