NSDateFormatter stringFromDate在模拟器中工作,而不是在iPad上工作(NSDateFormatter stringFromDate works in simulator

编程入门 行业动态 更新时间:2024-10-26 05:20:29
NSDateFormatter stringFromDate在模拟器中工作,而不是在iPad上工作(NSDateFormatter stringFromDate works in simulator not on iPad)

我有一个通用的应用程序,针对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.

更多推荐

本文发布于:2023-07-26 10:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1274352.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:是在   工作   而不   器中   stringFromDate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!