DateTime Comparison Precision

后端 未结 10 635
攒了一身酷
攒了一身酷 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:48

    You can convert them to String format and compare the string with each other.

    This also gives freedom to choose your comparison parameters, like only the time without the date, etc.

    if (String.Format("{0:ddMMyyyyHHmmss}", date1) == String.Format("{0:ddMMyyyyHHmmss}", date2))
    {
         // success
    }
    

提交回复
热议问题