Comparing certain components of NSDate?

前端 未结 4 459
青春惊慌失措
青春惊慌失措 2021-01-05 21:35

How would I compare only the year-month-day components of 2 NSDates?

4条回答
  •  情话喂你
    2021-01-05 22:07

    Since iOS 8 you can use -compareDate:toDate:toUnitGranularity: method of NSCalendar.

    Like this:

        NSComparisonResult comparison = [[NSCalendar currentCalendar] compareDate:date1 toDate:date2 toUnitGranularity:NSCalendarUnitDay];
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题