1.将时间戳转换成时间
- (NSString *)scx_toDateWithTimeStamp:(NSString *)timeStamp {
NSString *arg = timeStamp;
if (![timeStamp isKindOfClass:[NSString class]]) {
arg = [NSString stringWithFormat:@"%@", timeStamp];
}
NSTimeInterval time = [timeStamp doubleValue];
NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
NSLog(@"date:%@",[detaildate description]);
//实例化一个NSDateFormatter对象
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//设定时间格式,这里可以设置成自己需要的格式
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
return currentDateStr;
}
使用方法:
cell.textLabel.text = [NSString stringWithFormat:@"%@",[self scx_toDateWithTimeStamp:@"1461119340"]];