TFGRelativeDateFormatter 1.0.0

TFGRelativeDateFormatter 1.0.0

测试已测试
语言语言 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.hTFGRelativeDateFormatter.m 拖动到您的项目中。

联系方式

Thomas Guthrie @tomguthrie

许可证

TFGRelativeDateFormatter 依据 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。