Comparing NSDates without time component

后端 未结 17 1735
轮回少年
轮回少年 2020-11-27 12:49

In a swift playground, I have been using

NSDate.date() 

But, this always appears with the time element appended. For my app I need to ignor

17条回答
  •  野性不改
    2020-11-27 13:16

    In Swift 4:

    func compareDate(date1:Date, date2:Date) -> Bool {
        let order = NSCalendar.current.compare(date1, to: date2, toGranularity: .day)
        switch order {
        case .orderedSame:
            return true
        default:
            return false
        }
    }
    

提交回复
热议问题