I assumed that when subtracting 2 datetimes the framework will check their timezone and make the appropriate conversions.
I tested it with this code:
Console.WriteLine(DateTime.Now.ToUniversalTime() - DateTime.UtcNow.ToUniversalTime());
Console.WriteLine(DateTime.Now.ToUniversalTime() - DateTime.UtcNow);
Console.WriteLine(DateTime.Now - DateTime.UtcNow);
DateTime.Now - DateTime.UtcNow
System.DateTime does not hold time zone information, only a
.Kind property that specifies whether it is Local or UTC. But before .NET 2.0, there was not even a
When you subtract (or do other arithmetic, like
>, on) two
DateTime values, their "kinds" are not considered at all. Only the numbers of ticks are considered. This gives compatibility with .NET 1.1 when no kinds existed.
The functionality you ask for (and expect) is in the newer and richer type
System.DateTimeOffset. In particular, if you do the subtraction
DateTimeOffset.Now - DateTimeOffset.UtcNow you get the result you want. The
DateTimeOffset structure does not have a local/UTC flag; instead, it holds the entire time zone, such as +02:00 in your area.