我在我的MVC 5项目中使用Bootstrap 3 Datetimepicker 3.0.0 的原因不多。
有没有办法调整一周的开始时间,使其从周一开始?语言标记也无效。
$(function () {
$('#PickupTime').datetimepicker({
weekStart: 1
});
});
这不起作用是因为它不是相同的bootstrap-datapicker.js
我在我的MVC 5项目中使用Bootstrap 3 Datetimepicker 3.0.0 的原因不多。
有没有办法调整一周的开始时间,使其从周一开始?语言标记也无效。
$(function () {
$('#PickupTime').datetimepicker({
weekStart: 1
});
});
这不起作用是因为它不是相同的bootstrap-datapicker.js
moment.updateLocale('en', {
week: { dow: 1 } // Monday is the first day of the week
});
$('#DateTime').datetimepicker();
如果您正在使用旧版本的moment.js,请执行以下操作。moment.lang('en', {
week: { dow: 1 }
});
$('#DateTime').datetimepicker();
$('#myid').datetimepicker({
format:'YYYY-MM-DD',
locale: moment.locale('en', {
week: { dow: 1 }
}),
});
_week : {
dow : 1, // Sunday is the first day of the week.
doy : 6 // The week that contains Jan 1st is the first week of the year.
},
根据Datetimepicker的选项,这是不可能的。它只支持以下属性:
$.fn.datetimepicker.defaults = {
pickDate: true, //en/disables the date picker
pickTime: true, //en/disables the time picker
useMinutes: true, //en/disables the minutes picker
useSeconds: true, //en/disables the seconds picker
useCurrent: true, //when true, picker will set the value to the current date/time
minuteStepping:1, //set the minute stepping
minDate:`1/1/1900`, //set a minimum date
maxDate: , //set a maximum date (defaults to today +100 years)
showToday: true, //shows the today indicator
language:'en', //sets language locale
defaultDate:"", //sets a default date, accepts js dates, strings and moment objects
disabledDates:[], //an array of dates that cannot be selected
enabledDates:[], //an array of dates that can be selected
icons = {
time: 'glyphicon glyphicon-time',
date: 'glyphicon glyphicon-calendar',
up: 'glyphicon glyphicon-chevron-up',
down: 'glyphicon glyphicon-chevron-down'
}
useStrict: false, //use "strict" when validating dates
sideBySide: false, //show the date and time picker side by side
daysOfWeekDisabled:[] //for example use daysOfWeekDisabled: [0,6] to disable weekends
};
源链接:http://eonasdan.github.io/bootstrap-datetimepicker/#options
我使用了moment-with-langs.js替代了moment.js(我想它是ASP.NET MVC 5默认包的一部分)。
通过调用:
<script type="text/javascript">
$('#DateTime').datetimepicker({
language: "hr"
});
</script>
事情终于有所进展,日历最终从星期一开始了。
更新: 更好的方法是在web.config中添加键。
<appSettings>
<add key="Culture" value="hr" />
</appSettings>
然后
$(document).ready(function () {
$(document).on('focus', '#Date', function () {
$(this).datetimepicker({
locale: '@System.Configuration.ConfigurationManager.AppSettings["Culture"]',
format: 'DD:MM:YYYY',
});
});
});
'locale' => [
'firstDay' => 1
]
Datetimepicker有一个选项,可以设置为与您所在的世界地区相匹配(请参见locale选项http://eonasdan.github.io/bootstrap-datetimepicker/Options/#locale)
您也可以手动覆盖它
$('#DateTime').datetimepicker({
locale: moment.local('en')
});
我遇到了同样的问题,我正在使用:
并且,根据 user3928861 的答案,我在 moment.js 的第961行找到了答案,如下所示:
var defaultLocaleWeek = {
dow : 1, // Sunday is the first day of the week.
doy : 6 // The week that contains Jan 1st is the first week of the year.
};
Weekday()
函数。即moment(new Date()).weekday(6).format("MM/DD/YYYY")
,它给了我本周的星期日。 https://momentjs.com/docs/#/get-set/weekday/ - Digvijayad