Azure Website - UTC Time and Local Time


Key: Azure Website uses UTC time on the server

How to: show local time in website UI?

Solution:

#1 Use TimeZoneInfo to convert UTC to local time

var cetZone = TimeZoneInfo.FindSystemTimeZoneById("Central Europe Standard Time");         
var localTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, cetZone);

#2 Use app settings to always show local time in Azure Management

   in app settings, add the TimeZoneInfo Id value to the WEBSITE_TIME_ZONE attribute, then, the DateTime.Now() method will return local time instead of the default GMT

reference - http://blogs.msdn.com/b/waws/archive/2014/08/05/get-the-local-server-time-for-your-azure-web-site.aspx

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章