Javascript - 检测用户的语言环境是否设置为使用12小时或24小时时间格式 [英] Javascript -- Detect if user's locale are set to use 12-hour or 24-hour time format

查看:139
本文介绍了Javascript - 检测用户的语言环境是否设置为使用12小时或24小时时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一种方法是解析 new Date()。toLocaleString()
但是这在铬/ webkit中不起作用,因为它返回的字符串不依赖于用户的语言环境(请参阅 http://code.google.com/p/chromium/issues/detail?id=3607

我强调,我正在寻找一种仅适用于客户端的解决方案,该解决方案适用于铬合金。

解决方案

只要Chromium不能修复 toLocaleString(),就没有办法用铬来做到这一点。



对于Firefox和IE解析, toLocaleString()会提供这些信息。
$ b 编辑


显然 toLocalString()现已在Chrome中修复。因此解析 toLocaleString()是个解决方案。


One way to do that is to parse new Date().toLocaleString(). But this doesn't work in chromium/webkit since the string it returns isn't dependent of the user's locale (see bug report at http://code.google.com/p/chromium/issues/detail?id=3607)

I emphasize that I'm looking for a solution that is client side only and that works in chromium.

解决方案

As long as Chromium doesn't fix toLocaleString() there is no way to do that in chromium.

For Firefox and IE parsing toLocaleString() will give that information.

EDIT
Apparently toLocalString() is now fixed in Chrome. The parsing of toLocaleString() is therefore a solution.

这篇关于Javascript - 检测用户的语言环境是否设置为使用12小时或24小时时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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