Bootstrap 3 Datetimepicker 3.0.0 - 周一开始一周

时间:2014-06-25 13:55:08

标签: jquery twitter-bootstrap asp.net-mvc-5 datetimepicker eonasdan-datetimepicker

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

任何想法如何抵消周开始所以它从星期一开始?语言标记也无效。

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

这不起作用,因为它不是相同的bootstrap-datapicker.js

9 个答案:

答案 0 :(得分:30)

如果您从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();

答案 1 :(得分: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 
};

Source: http://eonasdan.github.io/bootstrap-datetimepicker/#options

如果您不想看周日,可以停用周末。

答案 2 :(得分: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. 
},

'陶氏化学'必须是1,本周从星期一开始。

答案 3 :(得分:4)

您还可以在调用datetimepicker()

时通过语言环境覆盖dow值
$('#myid').datetimepicker({
    format:'YYYY-MM-DD',
    locale:  moment.locale('en', {
        week: { dow: 1 }
    }),
});

答案 4 :(得分:3)

我没有使用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',
        });
    });
});

答案 5 :(得分:0)

'locale' => [
    'firstDay' => 1
]

答案 6 :(得分:0)

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

并且,根据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.
};

答案 7 :(得分:0)

Datetimepicker可以选择将其设置为匹配您在世界的任何位置(请参阅区域设置选项http://eonasdan.github.io/bootstrap-datetimepicker/Options/#locale

您可以手动覆盖它

$('#DateTime').datetimepicker({
    locale: moment.local('en')
});

答案 8 :(得分:-1)

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