【发布时间】:2011-06-11 21:18:06
【问题描述】:
我有以下 NSDateFormatter:
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMM. d, yyyy"];
NSLocale *usLocal = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setLocale:usLocal];
我有一个 while 循环,它从给定的开始日期开始,并将日期加一,直到达到特定的结束日期。
NSDate *d = start;
while(YES){
NSString *td = [dateFormatter stringFromDate:d];
NSLog(@"converted date %@ to %@",d,td);
...adds a date and re-initializes d
}
我得到如下输出:
2011-06-11 17:10:18.678 ListOf100[8784:707] converted date 2011-05-31 00:00:00 +0000 to May. 30, 2011
2011-06-11 17:10:18.687 ListOf100[8784:707] converted date 2011-06-01 00:00:00 +0000 to May. 31, 2011
2011-06-11 17:10:18.717 ListOf100[8784:707] converted date 2011-06-02 00:00:00 +0000 to Jun. 1, 2011
如您所见,所有日期都没有正确转换。他们都休息了 1 天。为什么会发生这种情况?我该如何解决?
【问题讨论】:
-
你能发布你如何重新初始化“d”吗?
-
这不是问题。即使是第一次也是错误的。
-
您应该向 Apple 报告此错误。我同意@Sai,您应该发布代码,以便我们测试它是否可重现。
标签: ios nsdate nsdateformatter