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

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

- (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;

}

你可能感兴趣的:(iOS如何转换十三位的时间戳)