iOS dev: NSDateFormatter problem
I have a source @"Tue, 06 Sep 2011 18:32:55 GMT" string and i have to parse it to NSDate.
i've tried in a following way and it works great on a simulators and devices <4 iOS version, but date object becomes nill on iphone 4 device.
NSString *dateString = [NSString stringWithFormat:@"Tue, 06 Sep 2011 18:32:55 GMT"]开发者_运维知识库;
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setDateFormat:@"EEE, d MMM yyyy HH:mm:ss zzz"];
NSDate *date = [df dateFromString:dateString];
i've also tried [df setDateFormat:@"#a, #d #b #Y %H:%M:S #x"], but the problem wasnt solved.
does anyone have some ideas?
My only guess is that you are not using the expected date format with your iOS4 Device.
Go into your "Settings" -> "General" -> "International" and check that the format used is the same as the other devices.
What I would still find weird though is that you are hard coding the NSString *dateString
in your example but still it could be the reason.
Have you done a setLocale: on the date formatter?
精彩评论