This is not a mistake in itself. DateTime doesn't care about the actual offset, and if you do any arithmetic of time, you should use UTC.
Example:
DateTime dt = new DateTime(2015, 3, 29, 2, 59, 0, DateTimeKind.Local); DateTime dt2 = dt.ToUniversalTime(); Console.WriteLine(dt.ToString()); Console.WriteLine(dt.AddMinutes(1).ToString()); Console.WriteLine(dt2.AddMinutes(1).ToLocalTime().ToString());
This will show the difference:
29.3.2015 2:59:00 29.3.2015 3:00:00 29.3.2015 4:00:00
Therefore, always indicate dates in UTC.
Or you can use DateTimeOffset , which remembers the actual offset. And you can convert to local time:
DateTimeOffset dt = new DateTime(2015, 3, 29, 2, 59, 0, DateTimeKind.Local); Console.WriteLine(dt.ToString()); Console.WriteLine(dt.AddMinutes(1).ToString()); Console.WriteLine(dt.AddMinutes(1).ToLocalTime().ToString());
Results:
29.3.2015 2:59:00 +02:00 29.3.2015 3:00:00 +02:00 29.3.2015 4:00:00 +03:00
source share