A long time ago I watched a WWDC session video where Apple introduced an API which would print a time interval in a humanly readable, localized form.
Instead of printing a date when someone posted a comment, it was very easy to print a localized string such as “2 hours ago” or “Yesterday” or “Last week”.
I can’t find that video anymore and no references or examples for this API. I’m sure that it was a dedicated API to directly get this kind of localized strings for date intervals relative to the current date.
I can’t remember the video (although there was some video about it) but I think the API you are thinking of is:
[NSDateFormatter localizedStringFromDate:date dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterNoStyle]I’m not sure if this API does relative date formatting and the frameworks mentioned by
Midhun MPtake this a lot furtherYou can, of course, construct your own
NSDateFormatterand set thesetDoesRelativeDateFormatting:YESproperty to provide text like “Today” or “Tomorrow”.Example code is in the class reference below in
setDoesRelativeDateFormatting:.See NSDateFormatterClassReference