I'm afraid I really don't understand how the .Net class DateTimehandles local timestamps (I live in Germany, so my language is de_DE). Perhaps someone can enlighten me a little; -)
The constructor DateTimecan be called using the parameters of the year, month, etc. Alternatively, a value may be provided DateTimeKind Local, Utcor Unspecified(= default).
Example:
DateTime a = new DateTime(2015, 03, 29, 02, 30, 00, DateTimeKind.Local);
DateTime b = new DateTime(2015, 03, 29, 02, 30, 00, DateTimeKind.Utc);
DateTime c = new DateTime(2015, 03, 29, 02, 30, 00, DateTimeKind.Unspecified);
DateTime d = new DateTime(2015, 03, 29, 02, 30, 00);
By definition, the values of c and d are identical. But if I compare everything with each other, all four are identical. Checking objects in the VS debugger shows that the value Ticks(s InternalTicks) are the same for everyone. However, the internal values dateDataare different, but the comparison operator is explicitly ignored.
As you can see, I built the value on March 29 of this year, 02:30. This point in time does not exist in our time zone, because it is skipped by switching to summer time. Therefore, I expected to get an exception for constructing the object a, but this did not happen.
In addition, it DateTimehas a method ToUniversalTime()that converts a value that is interpreted as local time for an equivalent UTC value. For testing, I ran the loop as follows:
DateTime dt = new DateTime(2015, 03, 29, 01, 58, 00, DateTimeKind.Local);
DateTime dtEnd = new DateTime(2015, 03, 29, 03, 03, 00, DateTimeKind.Local);
while (dt < dtEnd)
{
Log(" Localtime " + dt + " converted to UTC is " + dt.ToUniversalTime());
dt = dt.AddMinutes(1);
}
Result:
Localtime 29.03.2015 01:58:00 converted to UTC is 29.03.2015 00:58:00
Localtime 29.03.2015 01:59:00 converted to UTC is 29.03.2015 00:59:00
Localtime 29.03.2015 02:00:00 converted to UTC is 29.03.2015 01:00:00
Localtime 29.03.2015 02:01:00 converted to UTC is 29.03.2015 01:01:00
Localtime 29.03.2015 02:02:00 converted to UTC is 29.03.2015 01:02:00
...
Localtime 29.03.2015 02:58:00 converted to UTC is 29.03.2015 01:58:00
Localtime 29.03.2015 02:59:00 converted to UTC is 29.03.2015 01:59:00
Localtime 29.03.2015 03:00:00 converted to UTC is 29.03.2015 01:00:00
Localtime 29.03.2015 03:01:00 converted to UTC is 29.03.2015 01:01:00
Localtime 29.03.2015 03:02:00 converted to UTC is 29.03.2015 01:02:00
Thus .Net has no problem converting non-existent timestamps from local time to UTC. In addition, adding a minute to an existing local time stamp is not local and gives a nonexistent time stamp.
64- UTC, 4 , .
, UTC , .
: ( .Net)? DateTimeKind, ? , ( 23:59:60): -)