Reputation: 1113
I have string "24 Jan 2012 09:21:21 +0000" and I want to make it a NSDate object as
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterFullStyle];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"];
NSDate* date = [dateFormatter dateFromString:dateStr];
NSLog(@"%@",date);
gives me (null)
What i should do to get date in the format I want.
Upvotes: 1
Views: 91
Reputation: 150615
Since you have a specific date format, you can set your formatter up to match it.
dateString = @"24 Jan 2012 09:21:21 +0000";
[formatter setDateFormat:@"d MMM yyyy HH:mm:ss Z"];
date = [formatter dateFromString:dateString];
NSLog(@"Date: %@", date);
You can see the list of date specifiers here.
Upvotes: 2
Reputation: 3921
24 Jan 2012 09:21:21 +0000
[dateFormatter setDateFormat:@"dd MMM yyyy HH:mm:ss ZZZ"];
Upvotes: 1
Reputation: 19323
I don't have an obj C environment to verify, but your date string is "year month day" and the input you want to handle is "day (short)month year"
Upvotes: 0