Bootstrap 3 Datetimepicker 3.0.0 - make a week sta

2020-02-01 07:06发布

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

9条回答
smile是对你的礼貌
2楼-- · 2020-02-01 07:37

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.

查看更多
相关推荐>>
3楼-- · 2020-02-01 07:40

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')
});
查看更多
Explosion°爆炸
4楼-- · 2020-02-01 07:43

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',
        });
    });
});
查看更多
登录 后发表回答