在javascript中设置区域设置

在javascript中设置区域设置

本文介绍了在javascript中设置区域设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 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 ()和日期()。你可以使用它们。Two of the functions are setlocale() and date(). You can use them. 这篇关于在javascript中设置区域设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-02 02:07