DateTime Comparison Precision

后端 未结 10 607
攒了一身酷
攒了一身酷 2020-12-29 04:24

I\'m doing DateTime comparison but I don\'t want to do comparison at second, millisecond and ticks level. What\'s the most elegant way?

If I simply compare the DateT

10条回答
  •  执笔经年
    2020-12-29 04:36

    Very simple solution from my own code:

    TimeSpan timeDifference = presentLastSavedDate.Subtract(previousLastSavedDate);
    if (timeDifference.Seconds > 0)
    {
        return Content(HttpStatusCode.Conflict, ALREADY_CHANGED_MSG);
    }
    

提交回复
热议问题