I need a method to format a NSTimeInterval
(time span in seconds) into a string to produce something like "about 10 minutes ago", "1h, 20min", or "less than 1 minute".
-(NSString*) formattedTimeSpan:(NSTimeInterval)interval;
Target platform is iOS. Sample code is welcome.
You might want to refer to Facebook three20 framework. In their NSDateAdditions, they provided a few pretty formats for date. It might be better than you extend it.
Refer to the source at https://github.com/facebook/three20/blob/master/src/Three20Core/Sources/NSDateAdditions.m
- (NSString*)formatShortRelativeTime;
will give you "<1m", "50m", "3h", "3d"Here is one that formats the date in the style of Facebook:
https://github.com/nikilster/NSDate-Time-Ago
This is a category for NSDate. It's not exactly using an NSTimeInterval, well internally :) I assume you are working with timestamps.
Header file NSDate+PrettyDate.h
Implementation NSDate+PrettyDate.m