在javascript中设置区域设置 [英] Set a locale in javascript

查看:308
本文介绍了在javascript中设置区域设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery通过以下方式测试日期的有效期:

jQuery tests the validity of a date via:

!/Invalid|NaN/.test(new Date(value))

new Date(dateString)是与 Date.parse(dateString)相同,并使用浏览器/操作系统语言环境来解析字符串。

new Date(dateString) is the same as Date.parse(dateString) and uses browser/OS locale to parse the string.

尝试解析 DD / MM / YYYY 但是我收到一个错误,因为我的浏览器正在寻找 MM / DD / YYYY 。由于我的产品只能由 DD / MM 人使用,我想强制这种行为。

I'm trying to parse DD/MM/YYYY but I get an error because my browser is looking for MM/DD/YYYY. Since my product will be used only by DD/MM people, I want to force this behaviour.

我可以写一个自定义验证器,但是可以通过JavaScript更改浏览器区域设置吗?

I could write a custom validator, but is it possible to change the browser locale via JavaScript as well?

推荐答案

您不能更改由于EMCAScript 规范中没有此类功能。

You can't change the locale, as there is no such feature in the EMCAScript specification.

然而,在JavaScript中实现PHP功能有一个不错的包,名为 php.js

However, there is a nice package called php.js that implements PHP functions in JavaScript.

其中两个功能是 setlocale < a>()和日期()。你可以使用它们。

Two of the functions are setlocale() and date(). You can use them.

这篇关于在javascript中设置区域设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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