Swift 3 - Comparing Date objects

后端 未结 14 1550
野的像风
野的像风 2020-11-30 07:14

I\'m updating my app to Swift 3.0 syntax (I know it\'s still in beta but I want to be prepared as soon as it released).

Until the previous Beta of Xcode (Beta 5) I wa

14条回答
  •  感情败类
    2020-11-30 07:56

    To compare date only with year - month - day and without time for me worked like this:

         let order = Calendar.current.compare(self.startDate, to: compareDate!, toGranularity: .day)  
    
                          switch order {
                            case .orderedAscending:
                                print("\(gpsDate) is after \(self.startDate)")
                            case .orderedDescending:
                                print("\(gpsDate) is before \(self.startDate)")
                            default:
                                print("\(gpsDate) is the same as \(self.startDate)")
                            }
    

提交回复
热议问题