Cocoa-Touch: How do I see if two NSDates are in the same day?

后端 未结 12 667
走了就别回头了
走了就别回头了 2020-11-30 04:35

I need to know if two NSDate instances are both from the same day.

Is there an easier/better way to do it than getting the NSDateComponents and comparing day/month/y

12条回答
  •  无人及你
    2020-11-30 04:58

    In Swift:

    NSCalendar.currentCalendar().isDate(yourDate, equalToDate: yourOtherDate, toUnitGranularity: .Day)
    

    It will return true if they are on the same day.

提交回复
热议问题