Bootstrap datetimepicker没有默认初始值

时间:2017-03-29 16:15:55

标签: jquery css bootstrap-datepicker

我正在使用bootstrap datetimepicker我想删除默认的选定日期。

$("#datetimepicker1").datetimepicker({ format: 'MM/DD/YYYY', minDate:new Date() });

enter image description here

4 个答案:

答案 0 :(得分:6)

你可以为你的datetimepicer设置useCurrent:false,如

  $(document).ready(function () {
     var date = new Date();

     // subtract a day
     date.setDate(date.getDate() - 1);
     $('#datetimepicker1').datetimepicker({
          useCurrent: false, format: 'MM/DD/YYYY', minDate:date
     });
  });

JSFIDDLE

答案 1 :(得分:0)

通过查看他们的文档,您应该能够将useCurrent设置为false,默认情况下为true。 Source

$("#datetimepicker1").datetimepicker({
    format: 'MM/DD/YYYY',
    minDate: new Date(),
    useCurrent: false
});

答案 2 :(得分:0)

如果您打印出new Date(),您会理解它是一个日期时间,您应该设置为可以使用的日期(new Date()).toDateString()

var datetimepicker1 = $('#datetimepicker1').datetimepicker({
  format: 'YYYY-MM-DD',
  minDate: (new Date()).toDateString()
})

https://jsfiddle.net/dalinhuang/0Ltv25o8/4795/

或者您可以使用时刻js设置minDate ... 如果您使用useCurrent: false将排除'今天',请使用片刻或自己找到“日期”。

var datetimepicker1 = $('#datetimepicker1').datetimepicker({
  format: 'YYYY-MM-DD',
  minDate: moment().startOf('day')
})

https://jsfiddle.net/dalinhuang/0Ltv25o8/4793/

答案 3 :(得分:0)

I used two dates between these dates validating using datetimepicker.

   if ($("#toDate").val() != "") {
      $("#toDate").datetimepicker("destroy");
  }
  var fromDateFilt = new Date();
  if ($("#frmDate").val().length != 0) {
      fromDateFilt = this.convertDate($("#frmDate").val())
  }
  $('#toDate').datetimepicker({
      widgetPositioning: {
          horizontal: 'left'
      },
      icons: {
          time: "fa fa-clock-o",
          date: "fa fa-calendar",
          up: "fa fa-arrow-up",
          down: "fa fa-arrow-down",
          previous: 'fa fa-arrow-left',
          next: 'fa fa-arrow-right'
      },
      format: 'DD-MM-YYYY',
      minDate: fromDateFilt,
      maxDate: new Date()
  });
  this.psaReportForm.controls['frmDate'].setValue($("#frmDate").val());

public convertDate(date) {
  let dateArry = date.split("-");
  return new Date(dateArry[2], dateArry[1] - 1, dateArry[0]);
}