如何在jquery datetimepicker中设置mintime? [英] How to set mintime in jquery datetimepicker?
问题描述
我正在使用jquery datetimepicker。
i可以使用以下代码在当前时间之前禁用时间。
I am using jquery datetimepicker.
i am able to disable time before current time by using following code.
$("#startDate").datetimepicker({
dayOfWeekStart: 1,
minDate: 0,
format: 'd/m/Y H:i',
formatTime: 'H:i',
formatDate: 'd/m/Y',
startDate: currentDateTime,
ampm: true,
});
我有两个控件。 开始日期和结束日期。
条件:
当用户选择任何日期时间时, EndDate 的值将是一天半小时。
例如如果startdate是11-05-2016 18:00那么
endDate将是12-05-2016 18:30(用户将无法选择前一个时间到结束时间,即禁用时间到18 :00)
我已经实现了上述功能,但无法禁用时间。
我用时间js格式化日期。
我尝试过的事情:
I am having two controls. Start date and End date.
condition:
when user select any date time, value of EndDate will be a day and half an hour ahead.
e.g. if startdate is 11-05-2016 18:00 then
endDate will be 12-05-2016 18:30 (user will not be able to select previous time wrt to endDate time i.e. disable time upto 18:00)
I have achieved above functionality but fails to disable time.
I have used moment js to format date.
What I have tried:
var jsDate = moment($("#JobDate").val(), 'DD-MM-YYYY HH:mm');
var minimum = function(jsDate){
if(jsDate.getMinutes()==0){
this.setOptions({
minTime : jsDate.getHours()+":"+(parseInt(jsDate.getMinutes())+33),
});
}
else{
this.setOptions({
minTime : (parseInt(jsDate.getHours())+1)+":00",
});
}
};
$("#EndDate").datetimepicker({
startDate:datetime1,
onChangeDateTime:minimum,
onShow:minimum,
});
var dt = new Date(jsDate.add(1,'days'));
$("#startDate").val(dt.toString("DD-MM-YYYY HH:mm");
$来自jquery datetime教程的b $ b我尝试了上面的代码,但它没有用。
如果我使用 minTime:0 那么它是禁用前一个时间到当前时间。这在startDate的情况下确实很好。当我尝试禁用前一个时间到特定时间(从startDate选择的EndDate时间开始的可用时间),如上所示,它不起作用。 br $>
代码有什么问题?
from jquery datetime tutorial i tried above code but it's not working.
if I'm uses minTime : 0 then it is disabling previous time wrt to current time. and that is perfactly fine in the case of startDate. When i try to disable previous time wrt to specific time(i.e.disable time from startDate's selected time for EndDate) as shown above, its not working.
What's wrong with the code?
推荐答案
(#startDate)。datetimepicker({
dayOfWeekStart:1,
minDate:0,
格式:'d / m / YH:i',
格式时间:'H:i',
formatDate:'d / m / Y',
startDate:currentDateTime,
ampm:true,
});
("#startDate").datetimepicker({ dayOfWeekStart: 1, minDate: 0, format: 'd/m/Y H:i', formatTime: 'H:i', formatDate: 'd/m/Y', startDate: currentDateTime, ampm: true, });
我有两个控件。开始日期和结束日期。
条件:
当用户选择时等任何日期时间, EndDate 的价值将是一天半小时。
例如如果startdate是11-05-2016 18:00那么
endDate将是12-05-2016 18:30(用户将无法选择前一个时间到结束时间,即禁用时间到18 :00)
我已经实现了上述功能,但无法禁用时间。
我用时间js格式化日期。
我尝试过的事情:
I am having two controls. Start date and End date.
condition:
when user select any date time, value of EndDate will be a day and half an hour ahead.
e.g. if startdate is 11-05-2016 18:00 then
endDate will be 12-05-2016 18:30 (user will not be able to select previous time wrt to endDate time i.e. disable time upto 18:00)
I have achieved above functionality but fails to disable time.
I have used moment js to format date.
What I have tried:
var jsDate = moment(
(#JobDate)。val(),'DD-MM-YYYY HH:MM');
var minimum = function(jsDate){
if(jsDate.getMinutes()== 0){
this.setOptions({
minTime:jsDate.getHours()+ :+(parseInt(jsDate.getMinutes())+ 33),
});
}
else {
this.setOptions({
minTime:(parseInt(jsDate.getHours())+ 1)+:00,
}) ;
}
};
("#JobDate").val(), 'DD-MM-YYYY HH:mm'); var minimum = function(jsDate){ if(jsDate.getMinutes()==0){ this.setOptions({ minTime : jsDate.getHours()+":"+(parseInt(jsDate.getMinutes())+33), }); } else{ this.setOptions({ minTime : (parseInt(jsDate.getHours())+1)+":00", }); } };
(#EndDate)。datetimepicker({
startDate:datetime1,
onChangeDateTime:minimum,
onShow:最小,
});
var dt = new Date(jsDate.add(1,'days'));
("#EndDate").datetimepicker({ startDate:datetime1, onChangeDateTime:minimum, onShow:minimum, }); var dt = new Date(jsDate.add(1,'days'));
这篇关于如何在jquery datetimepicker中设置mintime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!