测试已测试 | ✓ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布上次发布 | 2014年12月 |
由 Thomas Guthrie 维护。
类似 Mail.app 的相对日期格式化器。
en_GB | en_US | |
---|---|---|
同一天 | 13:45 | 下午 1:45 |
昨天 | 昨天 | 昨天 |
同一周 | 星期一 | 星期一 |
同一年 | 3 月 15 日 | 3月15日 |
去年 | 22/04/2013 | 4/22/13 |
NSDate *date = ...;
TFGRelativeDateFormatter *formatter = [[TFGRelativeDateFormatter alloc] init];
NSString *relativeString = [formatter stringForDate:date];
该格式化器不是线程安全的(它内部使用 NSDateFormatter
),但提供了一个辅助方法 +sharedFormatter
,便于在主线程上获取相对日期字符串。
NSDate *date = ...;
NSString *relativeString = [[TFGRelativeDateFormatter sharedFormatter] stringForDate:date];
TFGRelativeDateFormatter 通过 CocoaPods 提供,要安装它,只需在 Podfile 中添加以下行:
pod 'TFGRelativeDateFormatter'
或者,直接将 TFGRelativeDateFormatter.h
和 TFGRelativeDateFormatter.m
拖动到您的项目中。
TFGRelativeDateFormatter 依据 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。