iOS如何转换十三位的时间戳

时间:2024-04-23 15:34:12

//将十三位的时间戳转换为日期

- (NSString *)getDate:(NSString *)jsonDate

{

//jsonDate类似这种/Date(1447659630000)/

NSArray *strArray = [jsonDate componentsSeparatedByString:@"("];

double timestampval =  [strArray[1] doubleValue]/1000;

NSTimeInterval timestamp = (NSTimeInterval)timestampval;

NSDate *updatetimestamp = [NSDate dateWithTimeIntervalSince1970:timestamp];

NSDateFormatter* formatter = [[NSDateFormatter alloc] init];

[formatter setDateFormat:@"yyyy-MM-dd"];

NSString *dateString = [formatter stringFromDate:updatetimestamp];

return dateString;

}