Comparing NSDates without time component

后端 未结 17 1750
轮回少年
轮回少年 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:22

    Swift 4

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

提交回复
热议问题