Swift 3 - Comparing Date objects

后端 未结 14 1535
野的像风
野的像风 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:45

    If you want to ignore seconds for example you can use

    func isDate(Date, equalTo: Date, toUnitGranularity: NSCalendar.Unit) -> Bool

    Example compare if it's the same day:

    Calendar.current.isDate(date1, equalTo: date2, toGranularity: .day)
    

提交回复
热议问题