Reputation: 11
- (NSDate*) parseTime:(NSString*) time
{
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMMM dd, yyyy hh:mm a"];
NSDate* date = [dateFormatter dateFromString:time];
return date;
}
Where time = "08 12, 2014 08:00 PM " and it is returning nil.
I'm new to this and have tried searching around on everything including Apples help docs, but could use a little more help here to finish pointing me in the right direction please.
Upvotes: 1
Views: 65
Reputation: 45490
Try adjusting like the following:
[dateFormatter setDateFormat:@"MM dd, yyyy hh:mm a"];
And dont forget to set the timezone on your formatter to avoid unexecpted result, for example:
dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"EDT"];
Very Important link by posted by @CrimsonChris:
LOCALE DATA MARKUP LANGUAGE (LDML)
Upvotes: 1