如何在web.config文件中更改我的asp.net网站的默认时区

Fad*_*lil 8 asp.net timezone web-config c#-4.0

我正在尝试更改我的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>
Run Code Online (Sandbox Code Playgroud)

Mat*_*int 19

改变文化并不会改变时区..NET中没有办法在每个应用程序的基础上更改时区.它只能在系统范围内更改.

许多服务器将其设置为UTC,但最佳做法是完全不依赖于系统时区.切勿使用DateTime.Now,TimeZoneInfo.Local,DateTimeKind.Local等从Web应用程序.

相反,使用DateTime.UtcNow,, DateTimeOffset.UtcNow或者如果您必须知道服务器的本地时间,请使用DateTimeOffset.Now.

如果您需要特定用户的本地时间,则需要知道他们的时区,并使用这些功能在TimeZoneInfo该特定区域和UTC之间进行转换.

在这里阅读更多.


Sup*_*deh 1

您将需要更改托管数据库的服务器的时区。您无法通过 web.config 来完成此操作。

以 UTC 格式存储日期/时间是最佳实践。请参考下面这篇文章。

https://web.archive.org/web/20201202215446/http://www.4guysfromrolla.com/articles/081507-1.aspx

希望这可以帮助。

(来源: http: //forums.asp.net/post/5060690.aspx