Reputation: 291
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>
Upvotes: 10
Views: 30403
Reputation: 241420
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.
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.
Instead, use DateTime.UtcNow
, DateTimeOffset.UtcNow
, or if you must know the server's local time, use DateTimeOffset.Now
.
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.
Read more here.
Upvotes: 24
Reputation: 1106
You will need to change the time zone of the server in which your database is hosted. You cannot do it through web.config.
Having the date/time stored in UTC format is a best practice. Refer to this article below.
https://web.archive.org/web/20201202215446/http://www.4guysfromrolla.com/articles/081507-1.aspx
Hope this helps.
(source: http://forums.asp.net/post/5060690.aspx)
Upvotes: 1