Here is an example that I ran with automatic DST enabled, run with in the Pacific Time (US & Canada) time zone:
dt1 = new DateTime(2009, 3, 8, 2, 30, 0, 0, DateTimeKind.Local);
string s1 = dt1.ToString("o");
DateTime dt2 = DateTime.Parse(s1, null, DateTimeStyles.RoundtripKind);
dt2 = DateTime.SpecifyKind(dt2, DateTimeKind.Local);
Console.WriteLine("Original DateTime: dt1: {0}", dt1.ToString("o");
Console.WriteLine("Round-tripped DateTime: dt2: {0}", dt2.ToString("o");
Which produces this output:
Original DateTime: dt1: 2009-03-08T02:30:00.0000000-08:00The time strings differ in that the original DateTime did not properly recognize that it should have been in DST (-07:00). My sense is that the dt1.ToString("o") function should have translated the input into DST (-07:00). The Parse function certainly does.
Round-tripped DateTime: dt2: 2009-03-08T03:30:00.0000000-07:00
Does anyone know how to successfully round-trip times specified within the DST switch range?
-Ray Kraft
Replies
Know the answer? Post it — somebody with the same question will find it here.