This will work:
TimeZoneInfo tzEasternZone = TimeZoneInfo.FindSystemTimeZoneById( "Eastern Standard Time"); DateTime utc = DateTime.Parse("2009-11-01T05:00:00Z", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind); bool isDaylight = tzEasternZone.IsDaylightSavingTime(utc);
There were two problems in the source code:
Although a UTC value was provided, it was converted to a local view in the Parse
statement. Therefore, ambiguity can be introduced there.
The IsDaylightTime
method in the DateTime
class will take a local time zone if the view is local or unspecified. After calling ConvertTime
result is unspecified, so it checked the local time zone rules, not the eastern time zone.
source share