iremk
iremk

Reputation: 677

Using NSDateFormatter dateFromString

I have a code :

NSString *dateStr = [currentElementValue stringByRemovingNewLinesAndWhitespace];

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EE, dd MMM yyyy hh:mm:ss ZZ"];

and i am receiving dates from server as string like :

Tue, 08 Jan 2013 13:21:54 +0000

but here's my problem , when i use : [dateFormat dateFromString:dateStr]

Mon, 07 Jan 2013 10:31:30 +0000 converted to 07-01-2013

but Wed, 02 Jan 2013 15:12:57 +0000 could not be converted.

anyone have any clue why is this happening?

any help would be appreciated. :)

Upvotes: 0

Views: 308

Answers (1)

user529758
user529758

Reputation:

This answer describes all the format specifiers in detail. hh stands for "hour (1-12, zero padded)" - so you can't write 15h here. If you wish to use a 24-hour time format, use HH instead.

[dateFormat setDateFormat:@"EE, dd MMM yyyy HH:mm:ss ZZ"];

Upvotes: 2

Related Questions