客户一周的第一天

发布于 2024-12-05 11:53:51 字数 62 浏览 3 评论 0原文

是否可以使用纯 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月寒剑心 2024-12-12 11:53:51

我无法为您找到任何开箱即用的解决方案,但如果您想坚持这一努力,您可能会发现以下有用的想法:

您可以使用 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.

薄暮涼年 2024-12-12 11:53:51

datejs 库可以执行类似的操作。另请查看此讨论

The library datejs can do things like that. Also check this discussion

从此见与不见 2024-12-12 11:53:51

唯一可靠的方法是询问访客。

<fieldset id="firstdayofweekFieldset">
<legend>First Day Of the Week</legend>
<label>Sunday <input type="radio" name="firstdayofweek" value="0" checked></label>
<label>Monday <input type="radio" name="firstdayofweek" value="1" ></label>
</fieldset>

The only sure way is to ask the visitor.

<fieldset id="firstdayofweekFieldset">
<legend>First Day Of the Week</legend>
<label>Sunday <input type="radio" name="firstdayofweek" value="0" checked></label>
<label>Monday <input type="radio" name="firstdayofweek" value="1" ></label>
</fieldset>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文