Calculate time difference in Cocoa

后端 未结 4 902
逝去的感伤
逝去的感伤 2021-02-04 08:53

I have got two timevalues in the format: %H%M%S (E.G.161500)

These values are text-based integers.

Is there a simple function in Cocoa that calculates the diffe

4条回答
  •  耶瑟儿~
    2021-02-04 09:41

    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:@"HHmmss"];
    
    NSDate *date1 = [dateFormatter dateFromString:@"161500"];
    NSDate *date2 = [dateFormatter dateFromString:@"171500"];
    
    NSTimeInterval diff = [date2 timeIntervalSinceDate:date1]; // diff = 3600.0
    

提交回复
热议问题