How to add seconds to Bootstrap date time picker

◇◆丶佛笑我妖孽 提交于 2019-12-07 07:03:20

问题


I am using the Bootstrap datatimepicker (https://eonasdan.github.io/bootstrap-datetimepicker/). It's great but it does not show or let the user select seconds.

$(document).ready(function () {
    $('#datetimepicker1').datetimepicker({defaultDate: new Date()});
});


<div class='input-group date' id='datetimepicker1'>
    <input type='text' class="form-control" />
    <span class="input-group-addon">
        <span class="glyphicon glyphicon-calendar"></span>
    </span>
</div>

So how to select seconds as well? And how to get seconds to show in the format? Currently it's 05/18/2017 1:26 PM, I want 05/18/2017 1:26:40 PM

In the dev guide, there is a fillSeconds() function but I am not sure how to apply it here.


回答1:


Setting the format to the correct value from moment and sideBySide:

$('#datetimepicker1').datetimepicker({
    defaultDate: new Date(),
    format: 'DD/MM/YYYY hh:mm:ss A',
    sideBySide: true
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<link rel="stylesheet"
  href="https://rawgit.com/Eonasdan/bootstrap-datetimepicker/master/build/css/bootstrap-datetimepicker.min.css">
<script src="https://rawgit.com/Eonasdan/bootstrap-datetimepicker/master/build/js/bootstrap-datetimepicker.min.js"></script>

<div class="container">
    <div class="row">
        <div class='col-sm-6'>
            <div class="form-group">
                <div class='input-group date' id='datetimepicker1'>
                    <input type='text' class="form-control"/>
                    <span class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
                    </span>
                </div>
            </div>
        </div>
    </div>
</div>



回答2:


$(document).ready(function () {
    $('#datetimepicker1').datetimepicker({
        defaultDate: new Date()});
}).fillseconds();

Try this way.



来源:https://stackoverflow.com/questions/44054324/how-to-add-seconds-to-bootstrap-date-time-picker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!