如何改变我的asp.net网站的web.config文件的默认时区 [英] How to change the default timezone of my asp.net website in web.config file
问题描述
我想改变我的asp.net网站的默认时区
我尝试了以下code,但没有奏效。
I'm trying to change the default time zone of my asp.net website and i tried the following code but it didn't work
<system.web>
<globalization culture="ar-JO" uiCulture="ar-JO" />
<httpRuntime maxUrlLength="10999" maxQueryStringLength="2097151" />
<compilation debug="true" targetFramework="4.0"/>
<customErrors mode="Off"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
推荐答案
改变文化不更改时区。有一个在.NET没办法更改时区上的每个应用程序。它只能改变系统范围。
Changing the culture does not change the time zone. There is no way in .NET to change the time zone on a per-application basis. It can only be changed system-wide.
许多服务器将其设置为UTC,但最好的做法是不依赖系统时区都没有。切勿使用 DateTime.Now
, TimeZoneInfo.Local
, DateTimeKind.Local
等,从Web应用程序。
Many servers set it to UTC, but the best practice is to not rely on the system time zone at all. Never use DateTime.Now
, TimeZoneInfo.Local
, DateTimeKind.Local
, etc. from a web application.
相反,使用 DateTime.UtcNow
, DateTimeOffset.UtcNow
,或者如果你必须知道服务器的本地时间,使用 DateTimeOffset.Now
。
Instead, use DateTime.UtcNow
, DateTimeOffset.UtcNow
, or if you must know the server's local time, use DateTimeOffset.Now
.
如果你需要一个特定用户的本地时间,那么你需要知道他们的时区,使用功能上的的TimeZoneInfo
到特定的区域和UTC之间进行转换。
If you need a particular user's local time, then you need to know their time zone, and use the functions on TimeZoneInfo
to convert between that specific zone and UTC.
了解更多 href=\"http://$c$cofmatt.com/2013/04/25/the-case-against-datetime-now/\">。
Read more here.
这篇关于如何改变我的asp.net网站的web.config文件的默认时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!