Why doesn't subtracting two local DateTime values appear to account for Daylight Saving Time?

前端 未结 3 1210
感情败类
感情败类 2021-01-06 05:12

I\'m playing with some C# code to try to gain an understanding of how subtracting DateTime objects in C# works with respect to Daylight Saving Time.

Per Google and o

3条回答
  •  遥遥无期
    2021-01-06 05:59

    So this is addressed in the MSDN documentation.

    Basicaly, when subtracting one date from another you should be using DateTimeOffset.Subtract() and not arithmetic subtraction as you have here.

    TimeSpan difference = fourAm.Subtract(oneAm);
    

    Yields the expected 2 hour time difference.

提交回复
热议问题