我正在尝试更改我的 asp.net 网站的默认时区
我尝试了以下代码,但它不起作用
<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 中无法针对每个应用程序更改时区。它只能在系统范围内更改。
许多服务器将其设置为 UTC,但最佳实践是根本不依赖系统时区。切勿使用DateTime.Now
, TimeZoneInfo.Local
, DateTimeKind.Local
等来自网络应用程序。
相反,使用DateTime.UtcNow
, DateTimeOffset.UtcNow
,或者如果您必须知道服务器的本地时间,请使用DateTimeOffset.Now
.
如果您需要特定用户的当地时间,那么您需要知道他们的时区,并使用TimeZoneInfo
在该特定区域和 UTC 之间进行转换。
阅读更多here.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)