marciokoko
marciokoko

Reputation: 4986

NSDate returning NULL

I have this datestring as logged in the console:

2013-8-11 10:00PM

Im running this dateFormatter in order to make it into an NSDate:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm a"];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"MST"]];

    NSDate *openDate = [dateFormatter dateFromString:adjustedOpenDateString];

    NSLog(@"DEALWITHTIMESTRINGS = open, now, close %@,%@,%@", openDate,[NSDate date], closeDate);

But when I log it, openDate shows up NULL. So does closeDate.

Upvotes: 0

Views: 373

Answers (1)

Charles A.
Charles A.

Reputation: 11123

The space between hh:mm and a in your format string is likely causing it to fail.

Instead you'll want to do this:

[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mma"];

Upvotes: 6

Related Questions