If you change your system clock

FROM: for example Hong Kong time or China Standard Time (UTC +8)

TO: EST Eastern Standard time (UTC -5)

Then below code will work.

DateTimeOffset don’t like "0001-01-01T00:00:00" if clock isn't set to EST?

string token = "0001-01-01T00:00:00";
if (!DateTimeOffset.TryParse(token, out var offsetDate))
{
   Console.WriteLine(“Why?”);
}

Why...?

1 Answers

3
Scott Hannen On

If your're on EST time then that value represents a UTC time greater than 1/1/0001 12:00:00 AM +00:00, which is the minimum value for DateTimeOffset. So you're okay.

If you're on Hong Kong time, the value would be less than DateTimeOffset.MinValue. The value can't be represented as a DateTimeOffset, so the TryParse fails.