我有 2 个数组,其中包含时间值。它们采用以下格式。 mm:ss:几百秒。我想得到数组中两个 [lastObjects] 之间的区别。 NSDate 不工作,因为最后一个值是百分之一秒。
一个问题。如果第二个日期大于第一个日期,它会给我一个负数,比如 -01:10:00 吗?
最佳答案
你的问题有两部分,解析时间和获取差异:
NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
[dateFormatter setDateFormat:@"mm:ss:SS"];
NSDate* firstDate = [dateFormatter dateFromString:@"01:00:00"];
NSDate* secondDate = [dateFormatter dateFromString:@"01:02:00"];
NSTimeInterval timeDifference = [secondDate timeIntervalSinceDate:firstDate];
关于iphone - 如何在 iPhone 中获取时差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1427151/