NSDateFormatter无法将字符串正确转换为日期

时间:2018-10-02 09:23:18

标签: ios objective-c timestamp nsdate nsdateformatter

下面的日期格式器提供了2017-10-01 23:00:00 +0000,而不是提供输出2016-12-25 23:00:00 +0000

// Convert string to date object
NSString *inputString = @"10-01-2017";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM-dd-YYYY"];
NSDate *outputDate = [dateFormat dateFromString:inputString];
NSLog(@"inputString={%@} outputDate={%@}",inputString, outputDate.description);

输出:

inputString={10-01-2017} outputDate={2016-12-25 23:00:00 +0000}

0 个答案:

没有答案