Compare two NSDates for same date/time [duplicate]
问题 This question already has answers here : How to compare two dates in Objective-C (14 answers) Closed 6 years ago . Is date1 == date2 not a valid way to compare? If not, what is the correct alternative? Here's my code: - (NSDate*) dateWithNoTime { unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; NSCalendar* calendar = [NSCalendar currentCalendar]; NSDateComponents* components = [calendar components:flags fromDate:self]; NSDate* dateOnly = [calendar