Jquery datetimepicker - Advance time by 1 hour

后端 未结 3 511
遇见更好的自我
遇见更好的自我 2021-01-15 08:35

I\'m currently using the jQuery datetimepicker add-on from here

It works just about perfectly, but I\'m stumped on how to add a small bit of functionality to it. I c

3条回答
  •  猫巷女王i
    2021-01-15 08:55

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

提交回复
热议问题