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

后端 未结 12 645
走了就别回头了
走了就别回头了 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 05:04

    in Swift 3.0, iOS8+

    if NSCalendar.current.isDate(Date(), equalTo: date, toGranularity: .day) {
    
    }
    

    or

    if NSCalendar.current.isDateInToday(date) {
    
    }
    

提交回复
热议问题