iOS_时间戳转化为日期TimeStamp转NSDate转NSString

2022-07-20 13:35:22 浏览数 (1)

代码语言:javascript复制
 //时间戳处理
NSInteger time = [self.album.updatedAt integerValue] / 1000;
NSNumber *timer = [NSNumber numberWithInteger:time];
NSTimeInterval interval = [timer doubleValue];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
//设置日期格式
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"yyyy-MM-dd"];
NSString *str = [formatter stringFromDate:date];
[formatter release];

0 人点赞