dotnet / dotnet/dotnet-api-docs

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

Open
#9,845 0 comments 0 reactions 0 assignees View on GitHub
area-System.DateTime Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

[DateTime.MinValue](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.minvalue?view=net-8.0) says:

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

[DateTime.MaxValue](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.maxvalue?view=net-8.0) 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](https://referencesource.microsoft.com/#mscorlib/system/datetime.cs,116):
```
public static readonly DateTime MinValue = new DateTime(MinTicks, DateTimeKind.Unspecified);
public static readonly DateTime MaxValue = new DateTime(MaxTicks, DateTimeKind.Unspecified);
```
- [.NET 8.0.4](https://github.com/dotnet/runtime/blob/v8.0.4/src/libraries/System.Private.CoreLib/src/System/DateTime.cs#L133): (`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](https://learn.microsoft.com/en-us/dotnet/standard/datetime/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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.