下面的日期格式器提供了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}