当点击今天按钮时,Bootstrap Date Time Picker未选择当前时间

Bootstrap Date Time Picker not selecting current time when the today button is hit?

本文关键字:Picker Time 选择 时间 Date Bootstrap 今天 按钮      更新时间:2023-09-26

启动日期时间选取器在点击今天按钮时没有选择当前时间?

http://jsfiddle.net/9osk7w2j/

<div class="row">
    <div class="col-md-12">
        <div class="form-group">
            <div class="input-group date" id="datetimepicker1">
                <input type="text" placeholder="datetimepicker" class="form-control" />
                <span class="input-group-addon">
                    <span class="glyphicon-calendar glyphicon"></span>
                </span>
            </div>
        </div>
    </div>
</div>
$('#datetimepicker1').datetimepicker({
    format: 'YYYY-MM-DD HH:mm',
    locale: 'en-au',
    showTodayButton: true,
});

"Matthew Malone"的回答是正确的。DateTimepicker在引导程序DateTimepicker v3中运行良好。但在v4中运行不正常。

所以你有两个选择。

1.使用bootstrap datetimepicker v3,它将立即工作。

2.通过代码中的小调整,您可以使用bootstrap datetimepicker v4获取当前日期时间。

$('#datetimepicker1').datetimepicker({
   format: 'YYYY-MM-DD HH:mm:ss',
   useCurrent: false
   }).on('dp.show', function() {
   if($(this).data("DateTimePicker").date() === null)
     $(this).data("DateTimePicker").date(moment());
   });
});

你可以查看https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1311针对v4的问题。

我测试了两种工作方式,都很好。

发现以前的版本4.15.35有效,而版本4.17.37无效!

http://jsfiddle.net/zf5h4mms/

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.15.35/js/bootstrap-datetimepicker.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>