在 jQuery UI Datepicker 中设置星期几?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1313317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set start day of the week in jQuery UI Datepicker?
提问by Rudi
I'm looking through the docs for the jQuery UI Datepicker (http://jqueryui.com/demos/datepicker/), but I can't find how to set the first day of the week as Monday.
我正在查看 jQuery UI Datepicker ( http://jqueryui.com/demos/datepicker/)的文档,但我找不到如何将一周的第一天设置为星期一。
Applying regional settings will set Monday as first day of the week, but this will also change the language.
应用区域设置会将星期一设置为一周的第一天,但这也会更改语言。
回答by Bijan
Here is an example config I use. Look at the last line with "firstDay: 1". I think using sytax like this to specify datepicker options looks better ;)
这是我使用的示例配置。查看带有“firstDay: 1”的最后一行。我认为使用这样的语法来指定日期选择器选项看起来更好;)
$('#datepickerfield').datepicker({
constrainInput: true, // prevent letters in the input field
minDate: new Date(), // prevent selection of date older than today
showOn: 'button', // Show a button next to the text-field
autoSize: true, // automatically resize the input field
altFormat: 'yy-mm-dd', // Date Format used
beforeShowDay: $.datepicker.noWeekends, // Disable selection of weekends
firstDay: 1 // Start with Monday
})
回答by Andy Gaskell
Try the firstDay option (in the options tab):
尝试 firstDay 选项(在选项选项卡中):
//getter
var firstDay = $('.selector').datepicker('option', 'firstDay');
//setter
$('.selector').datepicker('option', 'firstDay', 1);
回答by Mimouni
for using first day as monday :
将第一天用作星期一:
$(function() {
$( "#date_id" ).datepicker({ firstDay: 1 });
});
回答by Hallgeir Engen
You can also achieve this by creating your own localization file for your language along with your own settings. See this page for details: http://docs.jquery.com/UI/Datepicker/Localization
您还可以通过为您的语言创建您自己的本地化文件以及您自己的设置来实现这一点。有关详细信息,请参阅此页面:http: //docs.jquery.com/UI/Datepicker/Localization
回答by preetika
function getFirstDateOfThisWeek(d)
{
var TempDate = new Date(d || new Date());
TempDate.setDate(TempDate.getDate() + (@Config.WeekStartOn - 1 - TempDate.getDay() - 7) % 7);
return TempDate;
}
var StartDate = getFirstDateOfThisWeek(new Date()); //1st date of this week