15

我在 MVC 5 项目中使用 Bootstrap 3 Datetimepicker 3.0.0的原因很少。

知道如何抵消周开始,所以它从星期一开始吗?语言标签也不起作用。

 $(function () {
    $('#PickupTime').datetimepicker({
     weekStart: 1
    });
 });

这不起作用,因为它与 bootstrap-datapicker.js 不同

4

9 回答 9

32

如果您从 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();
于 2015-07-18T15:00:58.097 回答
6

您还可以在调用 datetimepicker() 时通过语言环境覆盖 dow 值

$('#myid').datetimepicker({
    format:'YYYY-MM-DD',
    locale:  moment.locale('en', {
        week: { dow: 1 }
    }),
});
于 2018-01-18T23:43:01.460 回答
4

根据 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

如果您不想看到星期天,您可以禁用周末。

于 2014-06-25T14:00:50.040 回答
4

我没有使用moment.js,而是使用了moment-with-langs.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',
        });
    });
});
于 2014-06-28T23:25:27.703 回答
4

我刚刚做了!在 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,并且一周从星期一开始。

于 2014-11-27T12:37:40.930 回答
0

打开jquery.datetimepicker.js并找到变量“ dayOfWeekStart ”并将其设置为1

于 2014-10-10T17:07:18.350 回答
0
'locale' => [
    'firstDay' => 1
]
于 2015-01-26T16:52:45.437 回答
0

Datetimepicker 有一个选项可以设置它以匹配您在世界上的任何地方(请参阅语言环境选项http://eonasdan.github.io/bootstrap-datetimepicker/Options/#locale

您可以手动覆盖它

$('#DateTime').datetimepicker({
    locale: moment.local('en')
});
于 2016-03-21T17:55:16.217 回答
0

我偶然发现了同样的问题,我正在使用:

  • Bootstrap3 日期时间选择器(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.
};
于 2015-08-04T21:07:23.300 回答