twitter-bootstrap 如何将秒添加到 Bootstrap 日期时间选择器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44054324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 00:51:45  来源:igfitidea点击:

How to add seconds to Bootstrap date time picker

javascriptjquerytwitter-bootstrapbootstrap-datetimepickereonasdan-datetimepicker

提问by gaetanoM

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.

我正在使用 Bootstrap datatimepicker ( https://eonasdan.github.io/bootstrap-datetimepicker/)。这很棒,但它不会显示或让用户选择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

那么如何选择秒呢?以及如何获得以格式显示的秒数?目前是05/18/2017 1:26 PM,我想要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.

开发指南中,有一个fillSeconds()功能,但我不知道如何在此处应用它。

回答by gaetanoM

Setting the formatto the correct value from momentand sideBySide:

moment和 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>

回答by Shuddh

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

Try this way.

试试这个方法。