How to detect if the current locale uses 12-hour or 24-hour time format?

牧云@^-^@ 提交于 2019-12-24 15:10:50

问题


I searched for an answer to this question, but all I found is how to show 12-hour versus 24-hour time format rather than when to do that.

My question is similar to this one: How to determine if current culture/locale uses am/pm or 24-hour time? but I want to know if we have similar structure to CurrentCulture or CultureInfo in Rails.

I believe with use of locales it should be possible, but I do not know how to do it or if there is any database explicitly mentioning which languages use military format (24-hour) and which use AM/PM format.


回答1:


According to this wikipedia article, in most English-speaking regions, particularly the United States, the Philippines and the United Kingdom and its former colonies, the 12-hour clock is the predominant form of stating the time. Here is the relevant excerpt from the article:

In most English-speaking regions, particularly the United States, the Philippines and the United Kingdom and its former colonies, the 12-hour clock is the predominant form of stating > the time with the 24-hour clock used in contexts where unambiguity and accurate timekeeping > are important, such as for public transport schedules. Nonetheless, usage is inconsistent: in the UK, train timetables will typically use 24-hour time, but road signs indicating time > restrictions (e.g. on bus lanes) typically use 12-hour time.

Therefore, I suggested by Sergio in the comment, you may want to use geolocation to determine the appropriate default for the user and then expose the setting in the user interface to let the user fine tune this setting.



来源:https://stackoverflow.com/questions/19144045/how-to-detect-if-the-current-locale-uses-12-hour-or-24-hour-time-format

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