Hi - I am working in C#.net - .Net fx is 2.0 which doesnot support converting between different time zones. I have wrote a scheduler based on UTC but it is giving errors of 1 hour in the DTS periods for London. I need some solution so that I can gat the correct time in any timezone relative to UTC with correct DST adjustments.
.NET does support converting UTCtime to local time:
DateTime currentServerTime = DateTime.UtcNow.ToLocalTime();
See here for more info.
Is changing to .NET 3.5 absolutely out of the question? It would make your life much, much easier. Otherwise, you're stuck with the plain TimeZone and DaylightSavings classes, as well as having to fetch the known timezones using P/Invoke.
William Stacey has a blog post with some code to do this - but I haven't tried it, so can't vouch for its accuracy. (In my experience he's usually pretty good though :) There are no doubt similar bits of code around if that one doesn't help you.
I believe that the API he's using doesn't have access to historical data, btw. In other words, it will assume that DST always kicks in on the first Sunday of October (or whatever the rule is) rather than knowing that the rule has changed over time. TimeZoneInfo in .NET 3.5 supports historical data where the OS does.
DateTime currentServerTime = DateTime.UtcNow.ToLocalTime(); only changes based on the current offset.
Date & Times from the past won't be accurate because of Daylight Savings.
In other words, If you save a date during daylight savings, then read it when daylight isn't in effect it will not be the same time.
I'm looking for a simple solution for this, if I one I'll post it.