Bootstrap 3 Datetimepicker 3.0.0 – 周从星期一开始
我在MVC 5项目中使用Bootstrap 3 Datetimepicker 3.0.0 https://www.nuget.org/packages/Bootstrap.v3.Datetimepicker/的原因很少。
任何想法如何抵消周开始,所以它从星期一开始。 语言标签也无效。
$(function () { $('#PickupTime').datetimepicker({ weekStart: 1 }); });
这不起作用,因为它不是相同的bootstrap-datapicker.js
如果您从v2.8.1开始使用moment.js,请在调用datetimepicker()之前添加以下代码。
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();
根据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.js中改变这一行:
_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. },
‘dow’必须是1,本周从星期一开始。
而不是使用moment.js我使用了moment-with-langs.js(我想它是默认包ASP.NET MVC 5)。
致电:
事情有效,最后日历从星期一开始。
更新:更好的是,添加web.config键
然后
$(document).ready(function () { $(document).on('focus', '#Date', function () { $(this).datetimepicker({ locale: '@System.Configuration.ConfigurationManager.AppSettings["Culture"]', format: 'DD:MM:YYYY', }); }); });
您还可以在调用datetimepicker()时通过语言环境覆盖dow值
$('#myid').datetimepicker({ format:'YYYY-MM-DD', locale: moment.locale('en', { week: { dow: 1 } }), });
'locale' => [ 'firstDay' => 1 ]
我偶然发现了同样的问题,我正在使用:
- Bootstrap3 Datetimepicker( 4.14.30 )
- 片刻( 2.10.3 )
并且,根据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. };
Datetimepicker有一个选项可以将其设置为匹配您在世界的任何位置(请参阅区域设置选项http://eonasdan.github.io/bootstrap-datetimepicker/Options/#locale )
您可以手动覆盖它
$('#DateTime').datetimepicker({ locale: moment.local('en') });
打开jquery.datetimepicker.js并找到变量“ dayOfWeekStart ”并将其设置为1
- 如何在从AJAX调用中附加表单时正确设置MVC 5不显眼的validation?
- 在asp.net MVC中进行AJAX调用后渲染视图
- “0x800a1391 – JavaScript运行时错误:’jQuery’未定义”错误
- 在MVC中如何通过jquery调用.ashx处理程序文件
- 使用$ .ajax或$ .post调用MVC 5 Controller方法
- 在MVC 5中刷新部分视图Div
- SignalR- Jquery:$ .connection.chathub返回undefined
- 使用Jquery Datepicker的DateFormat错误
- WebAPI Put返回HTTPResponseMessage null