Cannot find the right date format (NSDateFormatter) for this

本小妞迷上赌 提交于 2019-12-11 05:57:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!