客户一周的第一天
是否可以使用纯 JavaScript 确定客户端计算机的区域设置? 我需要得到一周的第一天。是周日还是周一。
Is it possible to determine regional settings of the client's machine, using pure javascript?
I need to get first day of the week. Is it Sunday or Monday.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我无法为您找到任何开箱即用的解决方案,但如果您想坚持这一努力,您可能会发现以下有用的想法:
您可以使用 JavaScript 中的以下函数之一检测浏览器的区域设置:
< a href="http://www.techrepublic.com/article/detect-foreign-language-support-using-javascript/5069931" rel="nofollow noreferrer">http://www.techrepublic.com/article/detect-foreign-language-support-using-javascript/5069931
然后,您必须将区域设置(语言)映射到首选的开始日期星期。您可以使用具有 I18N 支持的本地(服务器端)脚本语言在单独的源文件中创建 JavaScript 数组:
如何在 python 中确定一周的第一天
(显示 Java 和 Python 示例)
作为替代方案,YUI(一个 JavaScript 框架)提供了丰富的国际化框架。虽然它对于您的需求来说可能有点繁重,而且我找不到可以为您提供一周第一天的功能,但它可能对您的应用程序派上用场:
http://yuilibrary.com/yui/docs/intl/
您可以自己将一周的第一天属性添加到资源包中(或使用以下方式记录票证温度)。有关法语资源包的示例:
http://yui.yahooapis.com/combo?3.3.0/build/datatype/lang/datatype-date_fr-FR.js
还有一个 i18n 的 jQuery 插件支持:
http://plugins.jquery.com/project/jquery_i18n_properties
但看起来是这样它不附带可用的资源包。
I could not find any out-of-the-box solutions for you, but if you want to persist this endeavor you may find the following ideas useful:
You can detect the locale of the browser using one of the following functions in JavaScript:
http://www.techrepublic.com/article/detect-foreign-language-support-using-javascript/5069931
Then, you have to map the locale (language) to the preferred start day of the week. You could create JavaScript arrays in a separate source file using a local (server side) scripting language with I18N support:
How to determine the first day of week in python
(shows Java and Python example)
As an alternative, YUI, a JavaScript framework, provides a rich internationalization framework. Although it may be a bit heavy for your needs, and I couldn't find a function that would provide you the first day of the week, it may come in handy for your application:
http://yuilibrary.com/yui/docs/intl/
You can add the first day of the week attribute to the resource bundles yourself (or log a ticket with tem). For an example of the French resource bundle:
http://yui.yahooapis.com/combo?3.3.0/build/datatype/lang/datatype-date_fr-FR.js
There also is a jQuery plugin for i18n support:
http://plugins.jquery.com/project/jquery_i18n_properties
But it looks like that it doesn't come with usable resource bundles.
datejs 库可以执行类似的操作。另请查看此讨论
The library datejs can do things like that. Also check this discussion
唯一可靠的方法是询问访客。
The only sure way is to ask the visitor.