Relative string from NSDate

cocoa, nsdate, nsstring

Solution

NSDateFormatter will do a great deal of what is mentioned above by using setDoesRelativeDateFormatting: on an instance. From there, you can control the formatting using the date style and the time style to fine tune it to your needs.

If that doesn't get you what you need then check out SORelativeDateTransformer, it is an NSValueTransformer subclass that attempts to provide the same behavior you see with relative dates on SO.

Finally, if you want to roll your own or do more research here is the (likely) original question on the topic... yes it is question 11.

Problem

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 last month 6 months ago last year ```

Original source

Related problems