How do you compare DateTime objects using a specified tolerance in C#?

前端 未结 7 844
清酒与你
清酒与你 2020-12-29 20:07

By default C# compares DateTime objects to the 100ns tick. However, my database returns DateTime values to the nearest millisecond. What\'s the best way to compare two DateT

7条回答
  •  自闭症患者
    2020-12-29 20:37

    I usally use the TimeSpan.FromXXX methods to do something like this:

    if((myDate - myOtherDate) > TimeSpan.FromSeconds(10))
    {
       //Do something here
    }
    

提交回复
热议问题