dotnet/dotnet-api-docs

Remarks for DateTime.MinValue and DateTime.MaxValue say the values are equivalent to UTC but they use DateTimeKind.Unspecified

Opened this issue · 0 comments

DateTime.MinValue says:

The value of this constant is equivalent to 00:00:00.0000000 UTC, January 1, 0001, in the Gregorian calendar.

DateTime.MaxValue says:

The value of this constant is equivalent to 23:59:59.9999999 UTC, December 31, 9999 in the Gregorian calendar, exactly one 100-nanosecond tick before 00:00:00 UTC, January 1, 10000.

I interpreted this to mean that both MinValue and MaxValue use DateTimeKind.Utc, but that's not the case:

  • .NET Framework 4.8:
          public static readonly DateTime MinValue = new DateTime(MinTicks, DateTimeKind.Unspecified);
          public static readonly DateTime MaxValue = new DateTime(MaxTicks, DateTimeKind.Unspecified);
    
  • .NET 8.0.4: (DateTimeKind.Unspecified has value 0)
          public static readonly DateTime MinValue;
          public static readonly DateTime MaxValue = new DateTime(MaxTicks, DateTimeKind.Unspecified);
    

Whether DateTimeKind.Unspecified is equivalent to DateTimeKind.Utc seems to depend on what operation you perform: ToString("R") prints "GMT", but converting between time zones may treat DateTimeKind.Unspecified as either local time or UTC, depending on the conversion. For example, Console.WriteLine(System.DateTime.MinValue.ToUniversalTime().ToString("R")); prints Mon, 01 Jan 0001 06:00:00 GMT on a machine with a local time zone of CDT.