I’m trying to convert a nsstring to nsdate and I am getting a weird behavior.
I try to convert these dates:
2012-11-14 13:35:05
2012-11-14 13:33:53
2012-10-22 12:56:27
2012-10-22 12:56:23
and more…
with this code:
NSString *createdString = [conversationFromServer objectForKey:@"created"];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[formatter setTimeZone:gmt];
NSDate *created = [formatter dateFromString:createdString];
As you can see, the dates have the same pattern, but I can’t convert the first and the second date. If I log the results, all of them in string are correct, but in nsdate the first and the second ones is nil.
Any solution? Thanks in advance
Use HH in uppercase: