0

I cannot understand or find any information that could explain why there are two different time component output (12p.m and 11 a.m) for the following. Can somebody please explain.

        DateTime d1 = new DateTime(2015, 05, 15).ToUniversalTime();
        DateTime d2 = new DateTime(2015, 02, 02).ToUniversalTime();

        Console.WriteLine(d1.ToString()); //OUTPUTS - 1/05/2015 12:00:00 p.m.
        Console.WriteLine(d2.ToString()); //OUTPUTS - 1/02/2015 11:00:00 a.m.
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Amitesh
  • 677
  • 1
  • 10
  • 24

1 Answers1

1

The ToUniveralTime method converts from the local time zone where the code is running, to UTC.

Since time zones can change their offsets from UTC at different times of the year, the value can easily be different between two different dates - especially since one date is in the winter, and the other is in the summer, due to daylight saving time.

See also, the DST tag wiki, and "time zone != offset" in the timezone tag wiki.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575