我尝试过使用
$("#datetimepicker1").data("DateTimePicker").date('2017/04/23 23:34:23');
然后我得到错误无法读取未定义的属性日期。
还有其他方法来设定日期和时间吗?
答案 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>