How to add current datetimepicker and add second?

蓝咒 提交于 2019-12-11 06:04:18

问题


Demo and full code is like this : http://fiddle.jshell.net/TC6Gr/436/

My javascript code is like this :

$('#time-start').datetimepicker({
    format: 'mm/dd/yyyy hh:ii',
    autoclose: true,
    pickerPosition: "bottom-left",
    maxView: 3,
    minuteStep: 1
})

I want the code executed, it's will view current datetime. I want to view second too. So, second also viewed. The second also selected. I had searching response in google, but I don't find it. I'm still confused

Any solution to solve my problem?


回答1:


Try this:

Fiddle

HTML:

 <div class="col-sm-6 start-date">
   <div class='input-group date' id="time-end">
      <input type='text' id="time-start" class="form-control" placeholder="End Time" >
      <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
   </div>
</div>

Script:

Number.prototype.padLeft = function(base,chr){
   var  len = (String(base || 10).length - String(this).length)+1;
   return len > 0? new Array(len).join(chr || '0')+this : this;
}



    var d = new Date,
        dformat = [ (d.getMonth()+1).padLeft(),
                    d.getDate().padLeft(),
                    d.getFullYear()].join('/')+
                    ' ' +
                  [ d.getHours().padLeft(),
                    d.getMinutes().padLeft(),
                    d.getSeconds().padLeft()].join(':');
     $('#time-start').val(dformat);

$('#time-start').datetimepicker({
     format: 'mm/dd/yyyy hh:ii:ss',
    autoclose: true,
    pickerPosition: "bottom-left",
    maxView: 3,
    minuteStep: 1
})



回答2:


Try This

function getDateTime() {
    var now     = new Date(); 
    var year    = now.getFullYear();
    var month   = now.getMonth()+1; 
    var day     = now.getDate();
    var hour    = now.getHours();
    var minute  = now.getMinutes();
    var second  = now.getSeconds(); 
    if(month.toString().length == 1) {
        var month = '0'+month;
    }
    if(day.toString().length == 1) {
        var day = '0'+day;
    }   
    if(hour.toString().length == 1) {
        var hour = '0'+hour;
    }
    if(minute.toString().length == 1) {
        var minute = '0'+minute;
    }
    if(second.toString().length == 1) {
        var second = '0'+second;
    }   
    var dateTime = year+'/'+month+'/'+day+' '+hour+':'+minute+':'+second;   
     return dateTime;
}



回答3:


Just add second input for datetimepicker with id time-end and initialize datetimepicker for it too:

Demo: http://fiddle.jshell.net/wxoud40L/

<div class="col-sm-6 start-date">
   <div class='input-group date' id="time-end">
      <input type='text' class="form-control" placeholder="End Time" readonly>
      <span class="input-group-addon"><span class="glyphicon lyphicon-calendar"></span></span>
   </div>
</div>

Jquery

$('#time-end').datetimepicker({
    format: 'mm/dd/yyyy hh:ii:ss',
    timeFormat: 'hh:ii:ss',
    autoclose: true,
    pickerPosition: "bottom-left",
    maxView: 3,
    minuteStep: 1
});


来源:https://stackoverflow.com/questions/38501486/how-to-add-current-datetimepicker-and-add-second

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