Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Human friendly date descriptions with NSDate on iOS

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?

like image 586
cfischer Avatar asked Jun 13 '11 15:06

cfischer


2 Answers

On iOS 4 and later, use the doesRelativeDateFormatting property:

NSDateFormatter *dateFormatter = ...;
dateFormatter.doesRelativeDateFormatting = YES;
like image 105
Regexident Avatar answered Oct 15 '22 05:10

Regexident


Three20's NSDateAdditions:

https://github.com/pbo/three20/blob/master/src/Three20Core/Sources/NSDateAdditions.m

.. allows you to do that as well.

EDIT: In 2013, you really don't want to use Three20 anymore. Use Regexident's solution.

like image 24
magma Avatar answered Oct 15 '22 03:10

magma