Does anyone know of a library or something that will convert an NSDate into strings like the examples below?
1 hour ago
yesterday
last Thursday
2 days ago
la
DO NOT use your own custom string translation. Writing your own translation that does something like "3 seconds ago" not only has the problem of needing to be updated constantly, but it also does not localize into other languages.
Instead, use Apple's built in NSDateFormatter:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.doesRelativeDateFormatting = YES;
formatter.locale = [NSLocale currentLocale];
formatter.dateStyle = NSDateFormatterShortStyle;
formatter.timeStyle = NSDateFormatterShortStyle;
NSString *timeString = [formatter stringFromDate:self.date];
This will output something like "Today, 11:10 PM", or "7/17/14, 5:44 AM".