在iOS中计算格式hh.mm.ss的时间间隔

calculate time interval of format hh.mm.ss in iOS

我有 hh.mm.ss 格式的日期,现在我想要当前格式的两个时间之间的时差(以小时为单位)。这怎么能做到。

NSString *time1 = @"12.43.42"; NSString *time2 = @"07.54.43";

我想要以小时为单位的时间。

请按此关注

NSDateFormatter *df = [NSDateFormatter new];
df.dateFormat = @"hh.mm.ss";

NSDate *date1 = [df dateFromString:@"12.43.42"];
NSDate *date2 = [df dateFromString:@"07.54.43"];

NSTimeInterval secondsBetween = [date2 timeIntervalSinceDate:date1];

int numberOfHours = secondsBetween / (60 * 60);