将UIDatePicker从12小时制更改为24小时制 [英] Change UIDatePicker from 12 hour clock to 24 hour clock and back

查看:304
本文介绍了将UIDatePicker从12小时制更改为24小时制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,我在这里提出第一个问题只是一个简单的问题-我已经花了一天的时间阅读NSLocale和NSCalendar类的描述,但是我看不到这是否可行。

I'm sorry to make my first question here a bit of a simple one -- I've spent a day reading the NSLocale and NSCalendar class descriptions but I couldn't see if this was possible.

我在UIDatePickerModeDateAndTime模式下有一个UIDatePicker。当前正在根据用户的区域设置显示日期和时间,这是默认行为。

I have a UIDatePicker in the UIDatePickerModeDateAndTime mode. It is currently displaying date and time according to the user's locale, which is the default behavior.

我希望能够提供以12小时或24小时时间格式显示UIDatePicker的选项。检测用户当前正在使用的时间格式不是问题,但是我不清楚如何仅更改UIDatePicker的时间格式而不完全丢弃用户的语言环境设置(因为选择器还显示了本地化的日期)周和月)。 UIDatePicker支持设置区域设置和设置日历。

I would like to be able to offer the option to show the UIDatePicker in either 12-hour or 24-hour time format. Detecting which time format the user is currently using isn't a problem, but I'm not clear on how to change just the time format of UIDatePicker without entirely throwing out the user's locale settings (since the picker also displays the localized days of the week and months). UIDatePicker supports setting its locale and setting its calendar.

所以,问题一是我应该通过NSLocale还是NSCalendar尝试做这件事,而问题二是任何人都可以推荐一种隔离时间格式的方法,而不会浪费用户的其他语言环境设置。

So, question one is whether this is something I should be trying to do via NSLocale or NSCalendar, and question two is if anyone can recommend a way to isolate the time format without throwing out the rest of the user's locale settings.

感谢任何建议。

推荐答案

好吧,在阅读了最近两年其他人在这里提出的相同问题后,似乎没有办法这样做,因为UIDatePicker使用了用户的国家/地区设置,而不是用户的语言环境设置,并且不能通过编程方式覆盖该设置。我提出了一个错误。

OK, after reading the last two years' worth of others asking the same question here, it seems that there is no way to do this since the UIDatePicker uses the user's country setting instead of the user's locale setting, and that can't be overridden programmatically. I filed a bug.

这篇关于将UIDatePicker从12小时制更改为24小时制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆