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

2019-06-27 00:07发布

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条回答
Luminary・发光体
2楼-- · 2019-06-27 00:29

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.

查看更多
登录 后发表回答