简体   繁体   中英

How can I set the bootstrap-datetimepicker to Todays's date at 12AM

I am trying to use the bootstrap-datetimepicker to allow the users to select date and time value using an easy tool.

I created two pickers using bootstrap-datetimepicker and linked them together like so

//From Picker
$('#ActionForm_LocalFrom').datetimepicker({
    format: 'MM/DD/YYYY LT',
}).on("dp.change", function (e) {
    $('#ActionForm_LocalTo').data("DateTimePicker").minDate(e.date);
});

//To Picker
$('#ActionForm_LocalTo').datetimepicker({
    format: 'MM/DD/YYYY LT',
    useCurrent: false //Important! See issue #1075
}).on("dp.change", function (e) {
    $('#ActionForm_LocalFrom').data("DateTimePicker").maxDate(e.date);
});

I need to change default date time on $('#ActionForm_LocalFrom') to be set to 9/24/2016 12:00 AM and the default of $('#ActionForm_LocalTo') to 9/24/2016 11:59 PM . Note that 9/24/2016 is today's date.

How can I set the date to today's date and the time to 12:00AM for the "From" picker and "11:59 PM" for the "To" Picker?

Here is what I tried here but it is not working

//From Picker
$('#ActionForm_LocalFrom').datetimepicker({
    format: 'MM/DD/YYYY LT',
}).on("dp.change", function (e) {
    $('#ActionForm_LocalTo').data("DateTimePicker").minDate(e.date);
}).defaultDate(moment().startOf('day'));

//To Picker
$('#ActionForm_LocalTo').datetimepicker({
    format: 'MM/DD/YYYY LT',
    useCurrent: false //Important! See issue #1075
}).on("dp.change", function (e) {
    $('#ActionForm_LocalFrom').data("DateTimePicker").maxDate(e.date);
}).defaultDate(moment().endOf('day'));

Hope this JSFIDDLE helps you. I have used below code to set minDate

$('#ActionForm_LocalFrom').datetimepicker({
    format: 'MM/DD/YYYY LT',
    minDate: moment().startOf('day').hour(23).minute(59)
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM