可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
There are few reasons I use Bootstrap 3 Datetimepicker 3.0.0 in my MVC 5 project.
Any idea how to offset week start so it starts from Monday? Language tag also not working.
$(function () {
$('#PickupTime').datetimepicker({
weekStart: 1
});
});
This is not working because it is not the same bootstrap-datapicker.js
回答1:
If you are using moment.js from v2.8.1 onwards, add the below code before calling datetimepicker().
moment.updateLocale('en', {
week: { dow: 1 } // Monday is the first day of the week
});
$('#DateTime').datetimepicker();
If you are using old version of moment.js, do the following
moment.lang('en', {
week: { dow: 1 }
});
$('#DateTime').datetimepicker();
回答2:
You can also override the dow value via the locale when calling datetimepicker()
$('#myid').datetimepicker({
format:'YYYY-MM-DD',
locale: moment.locale('en', {
week: { dow: 1 }
}),
});
回答3:
According to the options for Datetimepicker this is not possible. It only supports the following properties:
$.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
};
Source: http://eonasdan.github.io/bootstrap-datetimepicker/#options
You can disable the weekend if you don't want to see sunday.
回答4:
I have just done! In moment.js change this line:
_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' MUST BE 1 and the week starts at Monday.
回答5:
Instead of using moment.js I used moment-with-langs.js (I guess it came with default package ASP.NET MVC 5).
By calling:
<script type="text/javascript">
$('#DateTime').datetimepicker({
language: "hr"
});
</script>
thing works, finally the calender starts from monday.
UPDATE:
Even better, add key to web.config
<appSettings>
<add key="Culture" value="hr" />
</appSettings>
and then
$(document).ready(function () {
$(document).on('focus', '#Date', function () {
$(this).datetimepicker({
locale: '@System.Configuration.ConfigurationManager.AppSettings["Culture"]',
format: 'DD:MM:YYYY',
});
});
});
回答6:
open jquery.datetimepicker.js and find variable "dayOfWeekStart" and set it to 1
回答7:
'locale' => [
'firstDay' => 1
]
回答8:
I stumbled upon the same question, and i'm using:
- Bootstrap3 Datetimepicker (4.14.30)
- Moment (2.10.3)
And, following the answer of user3928861 I found the answer on line 961 of moment.js as follows:
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.
};
回答9:
Datetimepicker has an option to set that to match wherever you are in the world (see the locale option http://eonasdan.github.io/bootstrap-datetimepicker/Options/#locale)
You can manually override it
$('#DateTime').datetimepicker({
locale: moment.local('en')
});