问题
I cannot convert this kind of strings to NSDate, please help me out here. What am I doing wrong below?
dateString = @"201302051614461";
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:@"YYYYMMddHHmmSSSSS"];
NSDate *date = [dateFormatter dateFromString:dateString];
NSLog(@"dateString: %@", dateString);
NSLog(@"date: %@", date);
This returns with an empty date.
回答1:
If I break it like this 2013 02 05 16 14 46 1
Then the format string is @"yyyyMMddHHmmssS
回答2:
@"yyyyMMddHHmmssS" -- YYYY will give you the wrong year in many cases, and capitol S is for fractional seconds.
来源:https://stackoverflow.com/questions/14712801/cannot-find-the-right-date-format-nsdateformatter-for-this