Alex Rivera | Logout

How can I format a date in Objective-C similar to the jquery.timeago library?

Asked 2011-10-18T15:37:51.367
20

I have a feed of items displayed in table cells, part of which is a date / timestamp in the past.

In Objective-C, how can I accomplish formatting them in the same manner as the jquery.timeago plugin on the web?

That is, taking in a date and outputting things like:

  • 'just now'
  • '2 minutes ago'
  • '24 days ago'
  • 'a month ago'

I see there is an NSDate extension class here with methods such as dateWithDaysBeforeNow, dateWithMinutesBeforeNow, etc, but if there is a library out there that has already done this I will use it.

EDIT: Further to this, if someone composes a method (takes a date, returns a string) that accomplishes this, either with this linked extensions library or another method, I will award them the answer.

EDIT 2 Bounty goes to whoever can write the fuzzy date algorithm in Objective-C.

Edit
Report

1 Answer

4

I wrote an NSDate category that returns time deltas in a human readable format (e.g., "4 weeks, 2 days"). You can download it here and tweak it to your needs: https://github.com/chriscdn/RHTools (look for NSDate+timesince).

answered 2011-11-24T17:11:27.187

Your Answer