如何设置内联引导日期时间选择器的日期

时间:2017-12-08 09:03:37

标签: bootstrap-4 bootstrap-datetimepicker eonasdan-datetimepicker

我尝试过使用

$("#datetimepicker1").data("DateTimePicker").date('2017/04/23 23:34:23');

然后我得到错误无法读取未定义的属性日期。

还有其他方法来设定日期和时间吗?

1 个答案:

答案 0 :(得分:2)

这是一个工作片段:

$('#datetimepicker1').datetimepicker({
    format: 'YYYY-MM-DD HH:mm:ss',
    inline: true,
    sideBySide: true
});


$("#datetimepicker1").data("DateTimePicker").date('2017/04/23 23:34:23');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js?ver=1"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.0/moment-with-locales.js"></script>
<script src="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/5a991bff/src/js/bootstrap-datetimepicker.js"></script>
<link href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/master/build/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

<div class="form-group">
    <div class="row">
        <div class="col-md-8">
            <div id="datetimepicker1"></div>
        </div>
    </div>
</div>