2019-01-08 iOS时间戳转换毫秒失败,采用偏方解决

- (NSNumber *)duration{
    /*
     "time":{"request":"2019-01-08 14:38:43:4","callback":"2019-01-08 14:38:46:466","connect":"2019-01-08 14:38:22:841"}
     */
//    NSDateFormatter * formatter = [[NSDateFormatter alloc ] init];
//    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss:SSS"]; //毫秒级转换
//    NSDate *startDate = [formatter dateFromString: _time.request];
//    NSDate *endDate = [formatter dateFromString: _time.callback];
//    NSTimeInterval detaSec = endDate.timeIntervalSince1970 - startDate.timeIntervalSince1970;
//    return detaSec <= 0? @0 : @(detaSec);
//时间转换有时可以  有时匹配不上 先使用偏方吧 还是字符串切割走起
    NSString *starStr = [_time.request componentsSeparatedByString:@":"][2];
    NSString *endStr = [_time.callback componentsSeparatedByString:@":"][2];
    NSInteger deta = endStr.integerValue - starStr.integerValue;
    return deta <= 0? @0 : @(deta);
}

你可能感兴趣的:(2019-01-08 iOS时间戳转换毫秒失败,采用偏方解决)