是否有框架或API将给定NSDate的时间间隔(如2m,3h,星期二,2014-06-01)提供给当前的NSDate。它广泛用于iMessages和Mail App。它也用在其他应用程序中,我只是看到在我尝试为自己编写一个框架之前是否有框架。
答案 0 :(得分:2)
我建议使用this类别。它对你正在寻找的东西非常有帮助。
例如这行代码:
NSString *displayString = [NSDate stringForDisplayFromDate:date];
产生以下类型的输出:
- ‘3:42 AM’ – if the date is after midnight today
- ‘Tuesday’ – if the date is within the last seven days
- ‘Mar 1’ – if the date is within the current calendar year
- ‘Mar 1, 2008’ – else ;-)