devdev101
devdev101

Reputation: 251

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];

Upvotes: 0

Views: 128

Answers (3)

codercat
codercat

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

Mani
Mani

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

nerowolfe
nerowolfe

Reputation: 4817

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

Upvotes: 2

Related Questions