0

Suppose right now, the date and time is 2015-01-10 10:30:00. I have a date in the past like 2015-01-10 08:30:00 and another like 2015-01-09 15:00:00.

Instead of displaying the date difference in number of days and seconds, I want to display something like 2 hours ago or Yesterday. If the date is too far away, something like December 2014 could be used. It's similar to the time in posts on popular social networks.

Is there an easy way or already existing piece of code for to achieve this or I will have to make my own implementation?

Thanks.

Edit: I'm working with objective-c. NSTimeInterval secondsBetween = [date2 timeIntervalSinceDate:date1]; will return the time in seconds. I am more in search of an existing solution/library

LS_ᴅᴇᴠ
  • 10,823
  • 1
  • 23
  • 46
Ketan
  • 123
  • 1
  • 1
  • 10
  • 1
    With what programming language? Have you already tried anything yourself? Can you show us some code you've tried? –  Jan 08 '15 at 09:29
  • I'm working with objective-c. `NSTimeInterval secondsBetween = [date2 timeIntervalSinceDate:date1];` will return the time in seconds. I am more in search of an existing solution/library. – Ketan Jan 08 '15 at 09:33
  • TTTTimeIntervalFormatter ? – Larme Jan 08 '15 at 09:41
  • the best way to achieve this is dividing `NSTimeInterval` between dates to number of second in week/day/hour but I can`t find this answer here – sage444 Jan 08 '15 at 09:52

0 Answers0