Fabio B.
Fabio B.

Reputation: 9400

Help with date formats

What's the correct format to parse this string:

"Mon, 14 Mar 2011 15:36:00 GMT"

into a NSDate using NSDateFormatter?

Upvotes: 0

Views: 159

Answers (2)

Erik Tjernlund
Erik Tjernlund

Reputation: 1983

NSString *dateStr = [NSString stringWithString:@"Mon, 14 Mar 2011 15:36:00 GMT"];
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
[dateFormat setDateFormat:@"EEE, d MMM yyyy HH:mm:ss zzzz"];
NSDate *date = [dateFormat dateFromString:dateStr];    

Upvotes: 0

Michaël
Michaël

Reputation: 6734

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss zzzz"];
NSDate *myDate = [dateFormatter dateFromString:strPubDate];

Upvotes: 2

Related Questions