Can anyone help make sense of this. Microsoft’s TimeZoneInfo class in 3.5 is telling me the following GMT date is not in Daylight savings for the Eastern timezone, but it is.
// Get Eastern Timezone
TimeZoneInfo tzEasternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
// Convert to EST
DateTime easternTime = TimeZoneInfo.ConvertTime(DateTime.Parse("2009-11-01T05:00:00Z"), tzEasternZone);
// Daylight saving IS in effect on this date, but Microsoft doesn't think so
Boolean isDaylight = easternTime.IsDaylightSavingTime();
Here are 2 websites saying it is in daylight savings:
http://www.timeanddate.com/worldclock/converted.html?month=11&day=1&year=2009&hour=5&min=0&sec=0&p1=0&p2=198
http://www.timezoneconverter.com/cgi-bin/tzc.tzc
See: TimeZoneInfo.IsDaylightSaving
Also you might look at this...
TimeZoneInfo.GetAmbiguousTimeOffsets Method
Returns information about the possible dates and times that an ambiguous date and time can be mapped to.
This will work:
The original code had two issues:
Even though a UTC value was being provided, it was getting converted to local kind in the
Parse
statement. So ambiguity could be introduced there.The
IsDaylightTime
method on theDateTime
class will assume the local time zone if the kind is local or unspecified. After callingConvertTime
, the result has unspecified kind, so it was checking against the rules of the local time zone, not the eastern time zone.TimeZoneInfo.GetUtcOffset(DateTime)
Correctly returns the offset with daylight savings factored in if the specified date is inside the period