How to set time zone for ASP.NET MVC 5 application?

北战南征 提交于 2019-12-10 16:46:38

问题


I have quite large web application, which is developed with ASP.NET MVC 5 and MsSql 2008. On my PC, I have +0700 UTC, but on my shared hosting I have other time zone.

This code gives me correct DateTime.

DateTime utcTime = DateTime.UtcNow;

string zoneID = "N. Central Asia Standard Time"; 

TimeZoneInfo myZone = TimeZoneInfo.FindSystemTimeZoneById(zoneID);
DateTime custDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, myZone);

Console.WriteLine(custDateTime.ToString());

Unfortunately, I have many places, where I work with date and time. I afraid, that I forget anywhere to change code.

Is there simple way to set right time zone for my web application?

P.S. All users of my application have same time zone.


回答1:


If Internationalization is important to you, you can use this.

I had very good results by understanding what was written there.

MVC Framework will know how to treat your country, language, currencies, date-times format, timestamps, etc.



来源:https://stackoverflow.com/questions/22245101/how-to-set-time-zone-for-asp-net-mvc-5-application

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