Human friendly date descriptions with NSDate on iOS

cfischer picture cfischer · Jun 13, 2011 · Viewed 8.1k times · Source

I want to display NSDates in a "human-friendly way", such as "last week", or "a few days ago". Something similar to Pretty Time for Java.

What's the best way to do this, subclassing NSDateFormatter? Before I go and reinvent the wheel, is there already some library for this?

Answer

Regexident picture Regexident · Jun 13, 2011

On iOS 4 and later, use the doesRelativeDateFormatting property:

NSDateFormatter *dateFormatter = ...;
dateFormatter.doesRelativeDateFormatting = YES;