Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default timezone of my asp.net website in web.config file

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>

like image 337
Fadi Khalil Avatar asked Oct 08 '13 07:10

Fadi Khalil


2 Answers

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.

like image 177
Matt Johnson-Pint Avatar answered Sep 17 '22 07:09

Matt Johnson-Pint


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.

http://www.4guysfromrolla.com/articles/081507-1.aspx

Hope this helps.

(source: http://forums.asp.net/post/5060690.aspx)

like image 39
Superzadeh Avatar answered Sep 21 '22 07:09

Superzadeh