NSInteger dateTime = [model.updatedAt integerValue];
dateTime = dateTime / 1000;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:dateTime];
NSLog(@"33333%@",date);
NSDate *currentDate = [NSDate date];
NSTimeInterval time = [currentDate timeIntervalSinceDate:date];
NSLog(@"%f",time);
if ((time / (24 *3600)) > 1 ) {
if((time / (24 * 3600)) < 15){
NSString *str = [NSString stringWithFormat:@"更新 %d 天前",(int)time / (24 * 3600)];
self.labelUpdateAt.text = str;
}else {
// 按某个格式将日期输出.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY/MM/dd"];
NSString *dateString = [dateFormatter stringFromDate:date];
NSLog(@"dateString:%@",dateString);
self.labelUpdateAt.text = dateString;
}
}else if ((time / 3600) > 1) {
NSString *str = [NSString stringWithFormat:@"更新 %d 小时前",(int)(time / 3600)];
self.labelUpdateAt.text = str;
}else if ((time / 60) > 1) {
NSString *str = [NSString stringWithFormat:@"更新 %d 分钟前",(int)(time / 3600)];
self.labelUpdateAt.text = str;
}else {
NSString *str = @"刚刚";
self.labelUpdateAt.text = str;
}
时间戳转换为日期的详细代码.
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- new Date() 构造函数里要传的是毫秒数,如果未传参数,将自动获得当前日期和时间。而我们之所以可以传日期进去...
- 最近因为项目需要,使用到了Excel表数据上传,遇到了一个让我非常头疼的问题,那就是excel表中的数据格式是日期...