如何检测当前语言环境使用的是12小时制还是24小时制? [英] How to detect if the current locale uses 12-hour or 24-hour time format?

查看:221
本文介绍了如何检测当前语言环境使用的是12小时制还是24小时制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了这个问题的答案,但是我发现的是如何显示12小时与24小时制的时间格式,而不是何时显示.

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.

我相信使用语言环境应该有可能,但是我不知道该怎么做,或者是否有任何数据库明确提及哪种语言使用军用格式(24小时制)以及哪种语言使用AM/PM格式. /p>

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.

推荐答案

根据此维基百科文章,在大多数说英语的地区,尤其是美国,菲律宾和英国及其前殖民地,12小时制是说明时间的主要形式.这是文章的相关摘录:

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:

在大多数说英语的地区,尤其是美国,菲律宾和 在英国及其以前的殖民地,"12小时制"是一种主要形式,它表示"24小时制的时间"是在明确和准确的计时非常重要的情况下使用的,例如公共交通时间表.尽管如此,用法还是不一致的: 在英国,火车时刻表通常会使用24小时制,但指示时间>限制(例如在公交专用道上)的路标通常会使用12小时制.

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.

因此,我在Sergio的评论中建议您使用地理定位为用户确定适当的默认值,然后在用户界面中显示该设置,以使用户可以微调此设置.

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.

这篇关于如何检测当前语言环境使用的是12小时制还是24小时制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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