This is an iOS, Objective-C, Cocoa Touch, iPhone, iPad category for NSDate. It gives NSDate the ability to report times like "A moment ago", "30 seconds ago", "5 minutes ago", "Yesterday", "Last Month", "2 Years Ago", and so on.
This functionality has variously been referred to as a "time ago", "time since", or "fuzzy date" feature.
NSDate+TimeAgo currently supports the following languages: en, es
- Add the files to your project (including the localization files)
- Import the header using
#import "NSDate+TimeAgo.h"
- Call the
timeAgo
method in the following way:
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:0] NSString *ago = [date timeAgo]; NSLog(@"Output is: \"%@\"", ago); 2011-11-12 17:19:25.608 Proj[0:0] Output is: "41 years ago"
Would be nice to
- add customization options (e.g., should it report seconds or just "a minute ago")
- add string customization
- have more localizations
- add a separate method that understands "Last Friday", etc.
- other
Released under ISC (similar to 2-clause BSD)
Originally based on code Christopher Pickslay posted to Forrst. Used with permission. http://twitter.com/cpickslay
Ramon Torres began support for internationalization/localization. Added es
strings. http://rtorres.me/