Jquery datetimepicker - Advance time by 1 hour

心不动则不痛 提交于 2019-12-01 11:25:10

The following will add one hour to the end-time datepicker.

$('#dtStartDate').datetimepicker({
    onSelect: function(){
       var startDate = $('#dtStartDate').datetimepicker('getDate'));
       var endDate = new Date(parseFloat(startDate.setHours(startDate.getHours()+1)))

       //Get the ending date datepart
       var endDateDatePart = endDate.getFullYear() + '/' + endDate.getMonth() + '/' + endDate.getDate();

       //calculate the ending date time part including AM/PM
       var endDateTimePart;
       if (endDate.getHours() > 12) { endDateTimePart = endDate.getHours()-12 + ':' + endDate.getMinutes() + ' PM';} else {endDateTimePart = endDate.getHours() + ':' + endDate.getMinutes() + ' AM';}
       $('#dtEndDate').datetimepicker('setDate', endDateDatePart + ' ' + endDateTimePart );
   }
});

yes, it extends the JQuery-UI Datepicker which has different callbacks to handle a selection

you can check out the onSelect documentation and use it on your timepicker

$('#example').datetimepicker({
    onSelect: function(){
              //add 1 hour to start time
        }
});

There is a Get and Set Datetime function shown near the bottom of the page.

var ex13 = $('#example13');

ex13.datetimepicker();

$('#example13_setdt').click(function(){
    ex13.datetimepicker('setDate', (new Date()) );
});

$('#example13_getdt').click(function(){
    alert(ex13.datetimepicker('getDate'));
});

Could you use that? Or course you'll have to add an hour to the getDate.

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