jQuery Bootstrap 3 Datetimepicker 3.0.0 - 从星期一开始一周

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24410685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 02:32:44  来源:igfitidea点击:

Bootstrap 3 Datetimepicker 3.0.0 - make a week start on Monday

jquerytwitter-bootstrapasp.net-mvc-5datetimepickereonasdan-datetimepicker

提问by HerGiz

There are few reasons I use Bootstrap 3 Datetimepicker 3.0.0in my MVC 5 project.

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

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

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

采纳答案by HerGiz

Instead of using moment.js I used moment-with-langs.js (I guess it came with default package ASP.NET MVC 5).

我没有使用 moment.js,而是使用了 moment-with-langs.js(我猜它带有默认包 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

更新:更好的是,将密钥添加到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',
        });
    });
});

回答by justinw

If you are using moment.js from v2.8.1 onwards, add the below code before calling datetimepicker().

如果您从 v2.8.1 开始使用 moment.js,请在调用 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.js,请执行以下操作

moment.lang('en', {
  week: { dow: 1 }
});

$('#DateTime').datetimepicker();

回答by DoctorAgon

You can also override the dow value via the locale when calling datetimepicker()

您还可以在调用 datetimepicker() 时通过语言环境覆盖道琼斯指数

$('#myid').datetimepicker({
    format:'YYYY-MM-DD',
    locale:  moment.locale('en', {
        week: { dow: 1 }
    }),
});

回答by Stefan

According to the options for Datetimepicker this is not possible. It only supports the following properties:

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

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

You can disable the weekend if you don't want to see sunday.

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

回答by user3928861

I have just done! In moment.js change this line:

我刚做完!在 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' MUST BE 1 and the week starts at Monday.

'dow' 必须为 1,一周从星期一开始。

回答by flarpy

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

回答by Tales Farias

I stumbled upon the same question, and i'm using:

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

And, following the answer of user3928861I found the answer on line 961 of moment.js as follows:

并且,按照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.
};

回答by Pierre

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)

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

You can manually override it

您可以手动覆盖它

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

回答by seaWolf

open jquery.datetimepicker.jsand find variable "dayOfWeekStart" and set it to 1

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