RGriffiths
RGriffiths

Reputation: 5970

NSDateFormatter not working to covert NSString to NSDate

I am using NSDateFormatter to get a date from an NSString I am confused as to why the following is not working:

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSDate *myDate = [df dateFromString: timeDateUpdated];

myDate remains nil and yet, as the image shows the timeDateUpdated appears to be of the correct format.

enter image description here

Upvotes: 0

Views: 12

Answers (1)

uraimo
uraimo

Reputation: 19851

Wrong format, use HH instead of hh.

The h directive is for hour in the am/pm format, will not work with 17.

See this comprehensive date formatting guide

Upvotes: 1

Related Questions