【问题标题】:Bootstrap 3 Datetimepicker 3.0.0 - make a week start on MondayBootstrap 3 Datetimepicker 3.0.0 - 从星期一开始一周
【发布时间】:2014-08-16 03:15:01
【问题描述】:

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

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

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

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 这按预期工作。将星期一显示为日历上的第一天。除此之外,我需要他们选择的任何日期的星期一和星期日。即如果他们选择 08/09/2018 (MM/DD/YYYY) 那么我需要 08/06/2018 和 08/12/2018 。获取我使用Weekday() 函数的那些。即moment(new Date()).weekday(6).format("MM/DD/YYYY"),它给了我本周的星期日momentjs.com/docs/#/get-set/weekday
    【解决方案2】:

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

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

    【讨论】:

    • 工作就像一个沙姆!谢谢
    【解决方案3】:

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

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

    【讨论】:

    • 但左栏仍然是星期天,人们期待星期一
    • 在 bootstrap-datapicker.js 中我已经抵消了名称,但只有名称被移动,而不是日期本身,所以整个日历是不正确的。 EAven treid 在 moment.js 中发生了变化,但同样的事情。
    • 有什么替代建议吗?
    • 最后我切换到github.com/smalot/bootstrap-datetimepicker,但会跟随第一个的发展。
    • 不,我没有。这是越野车,根本不工作。锣回原形。
    【解决方案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,并且该周从星期一开始。

    【讨论】:

      【解决方案5】:

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

      【讨论】:

        【解决方案6】:

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

        【讨论】:

        • OP 指的是Eonasdan Bootstrap-Datepicker。这与 jQuery 的 datepicker 无关。
        • 与OP的问题无关。
        • 不编辑,但用作选项 $(".dataPicker").datetimepicker({ dayOfWeekStart: 1 });
        【解决方案7】:
        'locale' => [
            'firstDay' => 1
        ]
        

        【讨论】:

          【解决方案8】:

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

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

          【讨论】:

            【解决方案9】:

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

            您可以手动覆盖它

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

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2017-12-14
              • 1970-01-01
              • 1970-01-01
              • 2012-11-27
              • 1970-01-01
              • 2013-09-23
              • 1970-01-01
              相关资源
              最近更新 更多