I\'ve got a timestamp as a string like:
Thu, 21 May 09 19:10:09 -0700
and I\'d like to convert it to a relative time stamp like
Use the NSDate class:
timeIntervalSinceDate
returns the interval in seconds.
Quick exercise to implement this in objective-c:
Then implement this pseudo code:
if (x < 60) // x seconds ago
else if( x/60 < 60) // floor(x/60) minutes ago
else if (x/(60*60) < 24) // floor(x/(60*60) hours ago
else if (x/(24*60*60) < 7) // floor(x(24*60*60) days ago
and so on...
then you need to decide whether a month is 30,31 or 28 days. Keep it simple - pick 30.
There might be a better way, but its 2am and this is the first thing that came to mind...