Reputation: 251
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];
Upvotes: 0
Views: 128
Reputation: 23271
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
Upvotes: 1
Reputation: 17585
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.
Upvotes: 0
Reputation: 4817
Use this date format [dateFormat setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss xx"];
Upvotes: 2