NSDateFormatter on ios 5 - any other way to use it?

I have code that worked before iOS 4.3.5, now it doesn't work in iOS 5:

//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]; 

Now the data is going (null). Does anyone know what I did wrong?

Hello!

EDIT:

I searched the NSDateFormatter.h file and found:

 // - (id)init; // designated initializer 

init is commented out, so I'm not allowed to use [[NSDateFormatter alloc] init] correctly? Is there any other way to instantiate ah NSDateFormatter?

+4
source share
3 answers

You can run NSDateFormatter with initWithDateFormat: allowNaturalLanguage:

Reference to the NSDateFormat Class

SO-Question The NSDateFormatter initialization method is deprecated?

Hope this helps?

0
source

Try this format:

 @"EEE, dd MMM yyyy HH:mm:ss vvvv" 

Documents are here.

http://unicode.org/reports/tr35/tr35-10.html#Date_Format_Patterns

0
source

So what does a dateString look like before doing anything with it?

This will help a lot.

-1
source

All Articles