Bootstrap-datetimepicker生成奇怪的静态月份编号

时间:2016-12-25 14:21:44

标签: twitter-bootstrap datetimepicker bootstrap-datepicker

我正在使用tarruda的bootstrap-datetimepicker,当我选择日期,日历选择日和年份罚款但产生一些奇怪的数字,如'54'月份,其中月值不应大于12,即使选择不同月份以前生成的数字没有变化。

我做了fiddle,问题与上面提到的相同。

$('#datepicker').datetimepicker({
  format: "dd/mm/yyyy",
  allowInputToggle: true,
  autoclose: true,
  pickTime: false
});

2 个答案:

答案 0 :(得分:2)

来自源代码:

  

var dateFormatComponents = {

     

...,

     

MM:{property:' UTCMonth',getPattern:function(){return'(0?[1-9] | 1 [0-2])\ b&#39 ;; }},

     

mm:{property:' UTCMinutes',getPattern:function(){return'(0?[0-9] | [1-5] [0-9])\ b& #39 ;;}},

     

...

所以正确的格式是:

***"dd/MM/yyyy"***

有关详细信息,您可以查看momentjs format

更新后的jsfiddle

摘录:



$('#datepicker').datetimepicker({
  format: "dd/MM/yyyy",
  allowInputToggle: true,
  autoclose: true,
  pickTime: false
});
$('#timepicker').datetimepicker({
  format: "hh:mm",
  allowInputToggle: true,
  autoclose: true,
  pickDate: false,
  pickSeconds: false
});

<link rel="stylesheet"
      href="https://tarruda.github.io/bootstrap-datetimepicker/assets/css/bootstrap-datetimepicker.min.css">
<link rel="stylesheet"
      href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>
<script src="https://tarruda.github.io/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.min.js"></script>
<script src="https://tarruda.github.io/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.pt-BR.js"></script>


<form class="" id="course-enroll-form" action="/lessons/dashboard/{{lesson.id}}" method="post">
    <p>Propose day</p>

    <div id="datepicker" class="input-append date">
        <input id="datetime" type="text" name="date" class="form-control" required="required"
               placeholder="Date: dd/mm/yyyy"/>
    <span class="add-on">
        <i data-time-icon="icon-calendar" data-date-icon="icon-calendar"></i>
    </span>
    </div>
    <p>Propose time</p>

    <div id="timepicker" class="input-append date">
        <input type="text" name="time" class="form-control" required="required" placeholder="Time: hh/mm"/>
    <span class="add-on">
                                        <i data-time-icon="icon-time" data-date-icon="icon-time"></i>
                                    </span>
    </div>
    <h6 id="course-enroll" class="bt-course">
        <button type="submit" name="button">Click to book</button>
    </h6>
</form>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

您需要在dd/MM/yyyy

上使用dd/mm/yyyy
$('#datepicker').datetimepicker({
  format: "dd/MM/yyyy",
  allowInputToggle: true,
  autoclose: true,
  pickTime: false
});

https://jsfiddle.net/uxoysa0y/2/