我有一个通用的应用程序,针对iPhone和iPad ,只支持iOS 6+
我有一段非常简单的代码来从NSDate时间并将其格式化以便显示:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"h:mm a"]; validFromField.text = [formatter stringFromDate:fromDate];日期为'01/01/2012 10:00' 01/2012 '01/01/2012 10:00' 00'inDate,在iPhone模拟器,iPad模拟器和真正的iPhone 4S上我得到'10:00 AM'的预期值
然而,在我的iPad(3,新iPad)上,我得到'10:00' ,好像格式化程序中的'a'被忽略了。
iPhone和iPad都运行iOS 6.0.1
有没有人遇到过这个问题,或者知道如何修复它?
I have a universal app, targeting both iPhone and iPad and only supporting iOS 6+
I have a very simple piece of code to pull the time from an NSDate and format it for display:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"h:mm a"]; validFromField.text = [formatter stringFromDate:fromDate];With a date of '01/01/2012 10:00' in fromDate, on the iPhone Simulator, iPad Simulator and real iPhone 4S I get the expected value of '10:00 AM'
However, on my iPad (3, new iPad) I get '10:00' as though the 'a' in the formatter is being ignored.
Both the iPhone and iPad are running iOS 6.0.1
Has anyone encountered this problem, or know how to fix it?
最满意答案
我在另一个SO问题中找到了我的问题的答案: 当iPad有24小时格式时,NSDateFormatter有不同的结果 ......
由Apple技术问答支持: http : //developer.apple.com/library/ios/#qa/qa1480/_index.html
因此,实质上如果设备设置为24小时时间,则忽略格式化程序中的'a'标志,并以24小时格式返回时间。
I found the answer to my question in another SO question here: NSDateFormatter has different results when iPad has a 24-hour format…
Backed up by the Apple Technical Q&A here: http://developer.apple.com/library/ios/#qa/qa1480/_index.html
So in essence if the device is set to 24 hour time then the 'a' flag in the formatter is ignored and the time will be returned in 24 hour format.
更多推荐
发布评论