[英]iOS6 TimeInterval bug
我有一些代碼可以在iOS 5中完美運行,但在iOS 6中卻無法正常工作。
這是TimeIntervalSinceDate方法...
我發現其他人有此問題,但沒有解決方案:
這是我的代碼:
NSString *origDate = @"2012-11-29 19:43:30";
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setFormatterBehavior:NSDateFormatterBehavior10_4];
[df setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *convertedDate = [df dateFromString:origDate];
[df release];
NSDate* sourceDate = [NSDate date];
NSLog(@"sourceDate: %@", sourceDate);
NSLog(@"convertedDate: %@", convertedDate);
NSTimeInterval ti = [ sourceDate timeIntervalSinceDate:convertedDate];
NSLog(@"interval double: %f", ti);
在iOS 5中,我將其作為值:
interval double: 711.113610
在iOS 6中,我得到:
interval double: 31623151.242078
有什么建議么?
謝謝
看看蘋果公司對日期格式化程序怎么說:
一個常見的錯誤是使用YYYY。 yyyy指定日歷年,而YYYY指定在ISO年周日歷中使用的年份(“年中的一周”)。 在大多數情況下,yyyy和YYYY產生相同的數字,但是它們可能不同。 通常,您應該使用日歷年。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.