0

这在使用 iOS4.0 编译之前工作正常,我不知道出了什么问题。

这就是问题所在。我从我的数据库发送我的应用程序分数,上面有日期/时间。我的目标是将其存储在 CoreData 中。当我使用下面的代码时,我得到一个空值的日期。

代码:

     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"US"];
        [dateFormatter setLocale:locale];
        [dateFormatter setDateFormat:@"MM/dd/yyyy HH:mm:ss ZZZ"];
        currentDownloadedScore.dateEntered = [dateFormatter dateFromString:self.currentValue];
        NSLog(@"Date CV: %@",self.currentValue);
        NSLog(@"Date: %@",[currentDownloadedScore.dateEntered description]);
        [locale release];
        [dateFormatter release];

这是调试器中的结果:

2010-07-16 08:15:35.741 MyApp[75003:207] Date CV: 07/16/2010 04:21:00 +00:00
2010-07-16 08:15:35.742 MyApp[75003:207] Date: (null)
2010-07-16 08:15:35.745 MyApp[75003:207] Date CV: 07/16/2010 01:09:26 +00:00
2010-07-16 08:15:35.749 MyApp[75003:207] Date: (null)

任何帮助表示赞赏!谢谢。

4

3 回答 3

2

我发现了这个问题。似乎ZZZ格式化的部分不再接受冒号:

作品:07/16/2010 04:21:00 +0000

不起作用:07/16/2010 04:21:00 +00:00

为了支持当前已发布的应用程序,我所做的只是搜索+00:00字符串中的部分并将其替换为+0000. 多田!有用!

于 2010-07-21T12:46:54.057 回答
0

NSDateFormatter 在 iOS4 中变得非常挑剔。This other SO question有同样的问题,并且有几个不同的解决方案。

于 2010-07-16T12:37:35.417 回答
0

我有同样的问题。对我来说,问题是我的 XML 提要中有一个换行符,所以这段代码为我修复了它:

[currentDate replaceOccurrencesOfString:@"\n" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0,[currentDate length])];

于 2010-07-17T12:27:04.333 回答