The UTC output time presented when applying the offset should be in the range of 0 to 10,000. Occurred on some computers

I have the following code in a windows storage application using c #

birthDateTimePicker.Date = DateTime.Now;
if (birthDateTimePicker.Date == DateTime.MinValue)
     {
      no_date_lable.Visibility = Visibility.Collapsed;
      birthDateTimePicker.Visibility = Visibility.Collapsed;
      }

Note: this line is birthDateTimePicker.Date = DateTime.Now; for example, the user will actually be selected or will come from the server.

But I get an exception on this line:

if (dt_born_dt == DateTime.MinValue)

What is the reason for the thrown exception:

The UTC time provided when applying the offset should be between year 0 and 10000.

Indeed, I tested this on three computers, and I got an error in one of them.

I changed my system time zone to (UTC-08: 00) Pacific Time (USA and Canada) and did not receive this exception at all, and the codes worked correctly!

, , (UTC + 03: 30) !

enter image description here

+4
2

@CodeCaster . - "DateTime.MinValue" UTC.

if (birthDateTimePicker.Date == DateTime.MinValue.ToUniversalTime())

, "birthDateTimePicker.Date" - DateTime, DateTimeOffset, .

.

+1

, dt_born_dt ( , birthDateTimePicker, , , , 1 [ 2015 , ], , ) Date, DateTimeOffset, +3:30, .

DateTime, :

birthDatePicker.Date = DateTime.MinValue;

DateTime.MinValue, DateTimeKind.Unspecified, UTC. , , GMT ​​+: GMT ​​ MinValue, , DateTime.MinValue to DateTimeOffset.

: DateTimeOffset.MinValue.

, try-catch Parse(Exact); TryParse(Exact).

+4

Source: https://habr.com/ru/post/1621405/


All Articles