Skip to content

Instantly share code, notes, and snippets.

@DonMag
Created August 14, 2015 17:40
Show Gist options
  • Save DonMag/0b2f27ffdfef2a676220 to your computer and use it in GitHub Desktop.
Save DonMag/0b2f27ffdfef2a676220 to your computer and use it in GitHub Desktop.
// compare Time - Hour Minute Second - between two dates, ignoring the date part
- (BOOL)isTime:(NSDate *)d1 equalTo:(NSDate *)d2 {
unsigned int flags = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* components1 = [calendar components:flags fromDate:d1];
NSDateComponents* components2 = [calendar components:flags fromDate:d2];
NSDate* timeOnly1 = [calendar dateFromComponents:components1];
NSDate* timeOnly2 = [calendar dateFromComponents:components2];
return [timeOnly1 isEqualToDate:timeOnly2];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment