Skip to content

Instantly share code, notes, and snippets.

@mamaz
Created March 10, 2014 08:40
Show Gist options
  • Save mamaz/9461509 to your computer and use it in GitHub Desktop.
Save mamaz/9461509 to your computer and use it in GitHub Desktop.
// Get string time duration from 2 different NSDate object
- (NSString *)getNaturalLanguageForDate:(NSDate *)date1 andDate:(NSDate *)date2 withCalendar:(NSCalendar *)sysCalendar
{
// Get conversion to months, days, hours, minutes
unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit;
NSDateComponents *breakdownInfo = [sysCalendar components:unitFlags fromDate:date1 toDate:date2 options:0];
NSString *duration = [NSString stringWithFormat:@"%@:%@", [breakdownInfo hour], [breakdownInfo minute]];
return duration;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment