gpt4 book ai didi

iphone - iOS6 时间间隔错误

转载 作者:行者123 更新时间:2023-11-28 20:26:49 27 4
gpt4 key购买 nike

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

有什么建议吗?

谢谢

最佳答案

看看 Apple 是怎么说 Date Formatters 的:

A common mistake is to use YYYY. yyyy specifies the calendar year whereas YYYY specifies the year (of “Week of Year”), used in the ISO year-week calendar. In most cases, yyyy and YYYY yield the same number, however they may be different. Typically you should use the calendar year.

关于iphone - iOS6 时间间隔错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13637472/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com