0

尝试将以下字符串转换为 NSDate - 我认为我的 DateFormatter 设置正确,但它不起作用:

NSString *dateToCheckString = @"Friday, Dec. 6, 2013 at 7:00 PM";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"eeee, MMM. dd, yyyy at hh a"];
NSDate *dateToCheckNSDate = [[NSDate alloc] init];
dateToCheckNSDate = [dateFormatter dateFromString:dateToCheckString];

// Log it out to see the result:
NSLog(@"Conversion yielded: '%@'", [dateToCheckNSDate description]);

我得到的输出是(null)

有任何想法吗?

4

1 回答 1

3

No it's not correct. dd is a padded day (06 in your example) so that should be just d. Also "7:00" does not match hh (which is padded hours). You are looking for h:mm

于 2013-10-13T20:34:29.220 回答