问题描述
我的代码在iOS 4.3.5之前有效,现在在iOS 5中无法正常工作:
I have a code that was working until iOS 4.3.5, now in iOS 5 it's not working:
//Example of date I'm using: Mon, 31 Oct 2011 15:57:55 BRST
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss vvvv"];
[formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];
NSString *dateString = [TBXML textForElement:[TBXML childElementNamed:@"pubDate" parentElement:XML]];
NSDate *data = [formatter dateFromString:dateString];
[formatter release];
现在,数据即将来临(null)。有人知道我做错了吗?
Now, data is coming (null). Does anybody know what I did wrong?
问候!
编辑:
我在文件NSDateFormatter.h中查找并找到:
I was looking in the file NSDateFormatter.h and I found:
// - (id)init; // designated initializer
初始化注释,因此我不允许使用[[NSDateFormatter alloc] init ] 对? ?是否有任何其他的方式来创建NSDateFormatter的啊比如
init is commented, so I am not allowed to use [[NSDateFormatter alloc] init] right? Is there any other way to create ah instance of NSDateFormatter ?
推荐答案
您可以初始化与initWithDateFormat的NSDateFormatter:allowNaturalLanguage:
You can init the NSDateFormatter with initWithDateFormat:allowNaturalLanguage:
SO-问题
希望有帮助吗?
这篇关于ios 5上的NSDateFormatter - 任何其他使用方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!