NSDateFormatter issue with date format in iOS 8

半世苍凉 提交于 2019-12-19 09:42:16

问题


I have an NSDateFormatter which I use to format an NSDate into a string. The following format does not work: ddMMyyyy_hhmmss_SSS. When I try to format an NSDate I get the following output: 18092014_08:49:03,638, which has a colon and a comma I didn't specify in the format. Note that in iOS 7 I never had this kind of problem. This is the code I'm using:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat: @"ddMMyyyy_hhmmss_SSS"];
NSString *dateString = [dateFormat stringFromDate:exportDate];

回答1:


iOS8 have serious problem with time format imo. I've just resolved a bug on my application (that i've never had with iOS7) going to settings -> general -> date time -> time format, switching it from 24 to 12 and then back to 24 and all started working again.

Try to make my same procedure, maybe it work also for you!




回答2:


I got problems with NSDateFormatter in iOS 8 too, and had to build a fix version for an app. You could read this. It basically takes to overwrite the default locale:

formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];

But it's best not to use it for formats you want to show to the user. Hope it helps!



来源:https://stackoverflow.com/questions/25907011/nsdateformatter-issue-with-date-format-in-ios-8

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