I'm looking for a way to change the time zone in asp, as I was searching, I figured the we can do it through web.config file, but didn't know how to set it to be sync with Jordan time.
Asked
Active
Viewed 385 times
1 Answers
0
What do you mean by "change the timezone"? The current timezone setting is a property of the Windows profile and so belongs to the user identity that your w3wp.exe process runs under. There is no per-thread setting like there is for CultureInfo.
In my applications when I need custom timezone support I store a TimeZoneInfo object as part of an application's user's settings (and stored in Session state). Internally all dates and times are UTC and I just convert these UTC values to local using the user's TimeZoneInfo instance during render-time. I suggest you do something similar:
// At user login or session start
Session["TimeZone"] = TimeZoneInfo.FindSystemTimeZoneById("Jordan Standard Time");
// Static helper extension method to make local
public static DateTime ToLocal(this DateTime utcDateTime) {
TimeZoneInfo tz = Session["TimeZone"];
return TimeZoneInfo.ConvertTimeFromUtc( utcDateTime, tz );
}
// Use in ASP.NET page
<%= myDateTimeValue.ToLocal() %>

Dai
- 141,631
- 28
- 261
- 374