Calculate difference between two dates returns a negative number

前端 未结 4 1125
予麋鹿
予麋鹿 2021-01-15 05:12

I am trying to calculate how many days there are between different dates. Like the topic says, I\'m getting a negative value. I guess I could just take the absolute value, b

4条回答
  •  迷失自我
    2021-01-15 06:01

    This is expected behavior.

    You should use the TimeSpan.Duration() method.

    It returns a new TimeSpan object whose value is the absolute value of the current TimeSpan object.

    http://msdn.microsoft.com/en-us/library/system.timespan.duration.aspx

提交回复
热议问题