c# - Deserialized DateTime value changes across different versions of the .NET framework -


when compile , run following program targeting .net framework 3.5, datetime that's printed screen 11/1/2006 7:05:00 pm. (i in central time zone.) if change project target .net framework 4.0 or higher , run program output of 11/1/2006 6:05:00 pm, 1 hour earlier.

i've noticed when using framework 3.5 if change computer's checkbox daylight saving time output changes 6:05 pm, when using framework 4.x making changes daylight saving time checkbox doesn't affect output of program.

what going on here , time "correct" time? why changing targeted framework affect that?

using newtonsoft.json; using system;  namespace test {     public class mydata     {         public datetime? activationdate { get; set; }     }      public class program     {         public static void main()         {             string json = "{ \"activationdate\":\"\\/date(1162425900000-0400)\\/\"}";              console.writeline(jsonconvert.deserializeobject<mydata>(json).activationdate);         }     } } 

i found similar question (datetime value different across different versions of .net framework) answer says locale settings , not framework causing issue. however, doesn't seem in accordance i'm witnessing program wherein changing nothing framework (and reinstalling nuget package newtonsoft json) seems affecting output.

after digging through numerous websites looking answer stumbled across https://blog.appliedis.com/2013/03/06/beware-daylight-saving-time-transitions-in-dot-net/ pointed me in right direction. turns out, .net framework 3.5 apparently didn't have clear picture on when daylight saving time ended in 2006 evidenced test program:

using system;  namespace test {     public class program     {         public static void main()         {             datetime begin = new datetime(2006, 10, 24);             while (begin < new datetime(2006, 12, 25))             {                 console.writeline(begin + " - " + begin.isdaylightsavingtime());                 begin = begin.adddays(1);             }         }     } } 

running program compiled against framework 3.5 gives following results:

10/24/2006 12:00:00 - true 10/25/2006 12:00:00 - true 10/26/2006 12:00:00 - true 10/27/2006 12:00:00 - true 10/28/2006 12:00:00 - true 10/29/2006 12:00:00 - true 10/30/2006 12:00:00 - true 10/31/2006 12:00:00 - true 11/1/2006 12:00:00 - true 11/2/2006 12:00:00 - true 11/3/2006 12:00:00 - true 11/4/2006 12:00:00 - true 11/5/2006 12:00:00 - true 11/6/2006 12:00:00 - false 11/7/2006 12:00:00 - false 11/8/2006 12:00:00 - false 11/9/2006 12:00:00 - false 11/10/2006 12:00:00 - false 11/11/2006 12:00:00 - false 

while running against framework 4.0 shows this:

10/24/2006 12:00:00 - true 10/25/2006 12:00:00 - true 10/26/2006 12:00:00 - true 10/27/2006 12:00:00 - true 10/28/2006 12:00:00 - true 10/29/2006 12:00:00 - true 10/30/2006 12:00:00 - false 10/31/2006 12:00:00 - false 11/1/2006 12:00:00 - false 11/2/2006 12:00:00 - false 11/3/2006 12:00:00 - false 11/4/2006 12:00:00 - false 11/5/2006 12:00:00 - false 11/6/2006 12:00:00 - false 11/7/2006 12:00:00 - false 11/8/2006 12:00:00 - false 11/9/2006 12:00:00 - false 11/10/2006 12:00:00 - false 11/11/2006 12:00:00 - false 

at least looks microsoft aware of issue. https://support.microsoft.com/en-us/kb/933509


Comments