My web app runs on .Net 3.5, all of the dates are saved on the DB in UTC time (not in user time).
When I want to display a date I convert it to user date (from UTC)
/开发者_如何学运维/Get the current datetime of the user exp: GMT TO ISRAEL +2
public static DateTime GetUserDateTime(DateTime dateUTC)
{
string userTzId = "Israel Standard Time";
TimeZoneInfo userTZ = TimeZoneInfo.FindSystemTimeZoneById(userTzId);
dateUTC = DateTime.SpecifyKind(dateUTC, DateTimeKind.Utc);
DateTime ret = TimeZoneInfo.ConvertTime(dateUTC, TimeZoneInfo.Utc, userTZ);
return ret;
}
Until now it worked fine but I have users from Israel (GMT +2), and Israel switched to Daylight saving time on 26/3/10 so now it's (GMT +3).
For some reason the TimeZoneInfo.ConvertTime don't know the Daylight saving time switch is on 26/3/10 so it still converts to GMT +2.
The strange thing is that on localhost it works fine, I set up a test page:
DateTime userdate = GetUserDateTime(DateTime.UtcNow);
string str2 = "UserDateTime = " + userdate.ToString("dd/MM/yy") + " " + userdate.ToString("HH:mm");
On the Server (windows 2003 set to UTC time) it shows the wrong time (+2):
UserDateTime = 27/03/10 21:38
On localhost (windows XP set to Israel Time) it shows the correct time (+3):
UserDateTime = 27/03/10 22:38
How can I update the TimeZoneInfo that the Daylight saving time switch in Israel was on the 26/3/10?
Thanks.
Well, Israel is significant. I read somewhere that DST start and end dates were decided each year, often after a long and acrimonious debate in the Knesset. Requiring Microsoft to issue an update for Windows so that the registry could be updated.
Was that done on this machine?
The relevant registry key is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Israel Standard Time\Dynamic DST. I've got a huge list of dates in there. This is a Vista + Win7 feature, not sure what happens on XP. The update probably needs to take care of it. Ask more questions about it at superuser.com
The daylisghtsave date in Israel is now the same every year. XP requires a KB patch to handle Israel but Vista and 7 should be fine in this regard.s
精彩评论