When I compile and run the following program targeting .NET Framework 3.5, the DateTime
that's printed to the screen is 11/1/2006 7:05:00 PM
. (I am in the Central time zone.) If I change my project to target .NET framework 4.0 or higher and run the program I get an output of 11/1/2006 6:05:00 PM
, 1 hour earlier.
I've noticed that when using Framework 3.5 if I change my computer's checkbox for Daylight Saving Time the output changes to 6:05 PM, but when using Framework 4.x making changes to the Daylight Saving Time checkbox doesn't affect the output of the program.
What is going on here and which time is the "correct" time? Why would changing the 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 this similar question (DateTime value is different across different versions of .NET framework) but the answer says that it is the locale settings and not the framework that are causing the issue. However, this doesn't seem to be in accordance with what I'm witnessing with my program wherein changing nothing but the framework (and reinstalling the Nuget package for Newtonsoft JSON) seems to be affecting the output.