如何为ASP.NET MVC 5应用程序时区?何为、应用程序、时区、NET

2023-09-06 11:18:31 作者:撕书狂魔i

我有相当大的web应用程序,这是开发的ASP.NET MVC 5和MSSQL 2008年在我的电脑,我有0700 UTC,但是在我的共享主机我有其他的时区。

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.

这code 给了我正确的日期时间。

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

不幸的是,我有很多的地方,在那里我有日期和时间的工作。我怕了,我忘了随时随地改变code。

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

有没有简单的方法来设置正确的时区,我的web应用程序?

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

P.S。我的应用程序的所有用户都具有相同的时区。

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

推荐答案

如果国际对你很重要,你可以使用的这个。

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

我通过了解那里写着什么有很好的效果。

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

MVC框架将知道如何对待你的国家,语言,货币,日期,时间格式,时间戳等。

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