我想检查到 2NSDate
秒,它们是否在同一日期(时间可以不同)。我目前拥有的是这样的:
- (NSPredicate*) predicateWithDate:(NSDate *)date {
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit ) fromDate:date];
//create a date with these components
NSDate *startDate = [calendar dateFromComponents:components];
[components setMonth:0];
[components setDay:1];
[components setYear:0];
NSDate *endDate = [calendar dateByAddingComponents:components toDate:startDate options:0];
return [NSPredicate predicateWithFormat:@"((ANY notes.date >= %@) AND (ANY notes.date < %@))",startDate,endDate];
}