客户一周的第一天

时间:2021-02-17 01:40:49

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.

是否可以使用纯javascript确定客户端机器的区域设置?我需要得到一周的第一天。是星期天还是星期一。

3 个解决方案

#1


1  

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:

您可以使用JavaScript中的下列函数之一检测浏览器的语言环境:

http://www.techrepublic.com/article/detect-foreign-language-support-using-javascript/5069931

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:

然后,您必须将locale(语言)映射到一周的首选开始日。您可以使用支持I18N的本地(服务器端)脚本语言在单独的源文件中创建JavaScript数组:

How to determine the first day of week in python

如何在python中确定一周的第一天

(shows Java and Python example)

(显示Java和Python示例)


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:

作为替代方案,YUI是一个JavaScript框架,它提供了一个丰富的国际化框架。虽然它可能对您的需求有点重,而且我找不到一个功能可以在一周的第一天提供给您,但是它可能会对您的应用有用:

http://yuilibrary.com/yui/docs/intl/

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:

您可以将周的第一天属性添加到资源包中(或者使用tem记录一张票)。以法国资源包为例:

http://yui.yahooapis.com/combo?3.3.0/build/datatype/lang/datatype-date_fr-FR.js

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:

还有一个jQuery插件支持i18n:

http://plugins.jquery.com/project/jquery_i18n_properties

http://plugins.jquery.com/project/jquery_i18n_properties

But it looks like that it doesn't come with usable resource bundles.

但是看起来它没有可用的资源包。

#2


0  

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>

#3


0  

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

库datejs可以做这样的事情。还要检查这个讨论

#1


1  

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:

您可以使用JavaScript中的下列函数之一检测浏览器的语言环境:

http://www.techrepublic.com/article/detect-foreign-language-support-using-javascript/5069931

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:

然后,您必须将locale(语言)映射到一周的首选开始日。您可以使用支持I18N的本地(服务器端)脚本语言在单独的源文件中创建JavaScript数组:

How to determine the first day of week in python

如何在python中确定一周的第一天

(shows Java and Python example)

(显示Java和Python示例)


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:

作为替代方案,YUI是一个JavaScript框架,它提供了一个丰富的国际化框架。虽然它可能对您的需求有点重,而且我找不到一个功能可以在一周的第一天提供给您,但是它可能会对您的应用有用:

http://yuilibrary.com/yui/docs/intl/

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:

您可以将周的第一天属性添加到资源包中(或者使用tem记录一张票)。以法国资源包为例:

http://yui.yahooapis.com/combo?3.3.0/build/datatype/lang/datatype-date_fr-FR.js

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:

还有一个jQuery插件支持i18n:

http://plugins.jquery.com/project/jquery_i18n_properties

http://plugins.jquery.com/project/jquery_i18n_properties

But it looks like that it doesn't come with usable resource bundles.

但是看起来它没有可用的资源包。

#2


0  

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>

#3


0  

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

库datejs可以做这样的事情。还要检查这个讨论