Set default time in bootstrap datetimepicker?

前端 未结 3 579
伪装坚强ぢ
伪装坚强ぢ 2021-01-20 06:12

How can I set the default Hours and minutes as \"00:00\". Here I want to set only time not date. I am using the following code for datetimepicker. In this code how can I set

相关标签:
3条回答
  • 2021-01-20 06:28

    Bootstrap datetimepicker uses moment library so make use of it like this,

    var dateNow = new Date();
    $('#current_date').datetimepicker({
        defaultDate:moment(dateNow).hours(0).minutes(0).seconds(0).milliseconds(0)
    });
    
    0 讨论(0)
  • 2021-01-20 06:32

    Simplified version of @Freddy's answer.

    var dateNow = new Date();
    $('#current_date').datetimepicker({
        defaultDate:moment(dateNow).startOf('hour')
    });
    

    startof can take various arguments. More details in MomentJS documentation.

    0 讨论(0)
  • 2021-01-20 06:38
    $('#datepicker').datetimepicker({
        format: "H:i",
        defaultTime: '00:00',
        pickSeconds: false,
        datepicker: false
    });
    

    http://jsfiddle.net/7q26juzu/

    0 讨论(0)
提交回复
热议问题