如何添加当前日期时间选择器和添加秒



演示和完整代码如下:http://fiddle.jshell.net/TC6Gr/436/

我的javascript代码如下:

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

我要执行代码,它将查看当前日期时间。我也想看第二张。所以,第二个也看了。第二个也选择了。我在谷歌上搜索过响应,但没有找到。我仍然对感到困惑

有解决我问题的办法吗?

试试这个:

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>

脚本:

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
})

试试这个

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;
}

只需为带有id时间结束的日期时间选择器添加第二个输入,并为其初始化日期时间选择器:

演示: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
});

相关内容

  • 没有找到相关文章