Search code examples
iosnsdateformatternscalendar

NSDateFormatter not recognizing dates


I have an array that contains some date strings. I'm using NSDateFormatter but the problem is that it recognizes some of the dates and do not recognize others while all of them have the same format!

for example it formats: Sat, 01 Feb 2014 08:44:00 +0430

But returns null for: Wed, 29 Jan 2014 17:40:00 +0430

this is the code i used:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EEE, dd MMM yyyy hh:mm:ss xx"];
NSDate *date = [dateFormat dateFromString:dateInput];

Solution

  • Use this date format [dateFormat setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss xx"];