Set default time in bootstrap datetimepicker?

2019-02-27 03:40发布

How can I set the default Hours and minutes as "00:00". Here I want to set only time not date. I am using the following code for datetimepicker. In this code how can I set the default time as "00:00"?

    $('#timepicker'+rowIndx).datetimepicker({
				format : "dd/MM/yyyy hh:mm",										
				pickSeconds:false, 		
	}).on("show",function(e) {
		if($("#from_Date"+ rowIndx).val() == ""){		                                                   $('#timepicker'+rowIndx).datetimepicker("setDate", "");					
	}																
	}).on('changeDate', function(e) {
				isExtraTcAmountDateChanged = "Y";
	});

3条回答
放荡不羁爱自由
2楼-- · 2019-02-27 03:55
$('#datepicker').datetimepicker({
    format: "H:i",
    defaultTime: '00:00',
    pickSeconds: false,
    datepicker: false
});

http://jsfiddle.net/7q26juzu/

查看更多
疯言疯语
3楼-- · 2019-02-27 04:00

Bootstrap datetimepicker uses moment library so make use of it like this,

var dateNow = new Date();
$('#current_date').datetimepicker({
    defaultDate:moment(dateNow).hours(0).minutes(0).seconds(0).milliseconds(0)
});
查看更多
一纸荒年 Trace。
4楼-- · 2019-02-27 04:12

Simplified version of @Freddy's answer.

var dateNow = new Date();
$('#current_date').datetimepicker({
    defaultDate:moment(dateNow).startOf('hour')
});

startof can take various arguments. More details in MomentJS documentation.

查看更多
登录 后发表回答