
- (Nsstring *)formattedDate:(NSDate *)date{ NSTimeInterval timeSinceDate = [[NSDate date] timeIntervalSinceDate:date]; // print up to 24 hours as a relative offset if(timeSinceDate < 24.0 * 60.0 * 60.0) { NSUInteger houRSSinceDate = (NSUInteger)(timeSinceDate / (60.0 * 60.0)); switch(houRSSinceDate) { default: return [Nsstring stringWithFormat:@"%d hours ago",houRSSinceDate]; case 1: return @"1 hour ago"; case 0: NSUInteger minutesSinceDate = (NSUInteger)(timeSinceDate / 60.0); /* etc,etc */ break; } } else { /* normal NSDateFormatter stuff here */ }} 所以这是打印’x分钟前’或’x小时前’从日期起24小时,通常是一天.
总结以上是内存溢出为你收集整理的iOS – 友好的NSDate格式全部内容,希望文章能够帮你解决iOS – 友好的NSDate格式所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)