0

我有一些代码在 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

有什么建议么?

谢谢

4

2 回答 2

3

看看 Apple 对Date Formatters的评价:

一个常见的错误是使用 YYYY。yyyy 指定日历年,而 YYYY 指定年份(“一年中的一周”),用于 ISO 年-周日历。在大多数情况下,yyyy 和 YYYY 产生相同的数字,但它们可能不同。通常,您应该使用日历年。

于 2012-11-30T01:07:26.660 回答
0

iOS 在 5.1 和 6 之间切换了 Unicode 版本。

iOS 6.0 - 使用tr35-25而不是tr35-19

于 2012-11-30T01:10:15.637 回答