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;
}
网友评论