Question

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];
Was it helpful?

Solution

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

OTHER TIPS

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

Note:

HH is denoted by 24 hour format

hh is is denoted by 12 hour format

Try this

[dateFormat setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss xx"];

Because, HH is syntax for 24 hour format which is suitable for your criteria.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top