How to check if a DateTime occurs today?

后端 未结 13 1251
故里飘歌
故里飘歌 2020-12-08 18:01

Is there a better .net way to check if a DateTime has occured \'today\' then the code below?

if ( newsStory.WhenAdded.Day == DateTime.Now.Day &&
             


        
相关标签:
13条回答
  • 2020-12-08 18:49

    well, DateTime has a "Date" property and you could just compare based on that. But looking at the docs it seems that getting that property actually instantiates a new datetime with the time component set to midnight, so it may very well be slower than accessing each individual component, although much cleaner and more readable.

    0 讨论(0)
提交回复
热议问题