如何在datetimepicker中禁用之前和即将到达特定日期的日期? [英] How to disable dates previous and upcoming to specific date in datetimepicker?
问题描述
我正在使用jquery日期时间选择器。
我想禁用特定日期之前的日期选择日期。
例如
如果我的日期是2016年3月13日,
日历从此日期开始,结束日期当前日期即2016年5月13日。
用户不应该在2016年3月13日之前和2016年5月13日之后选择日期。 />
我尝试过:
var t = $(#preDate)。val();
var jsDate = new Date(t);
var time = new Date()。getTime();
var currentdate = new日期(时间);
var datetime1 = - + jsDate.getDate()+/+(jsDate.getMonth()+ 1)+/+ jsDate.getFullYear();
var datetime2 = currentdate.getDate()+/+(currentdate.getMonth()+ 1)+/+ currentdate.getFullYear();
$(#myDtPicker)。datetimepicker({
minTime:0,
minDate:datetime1,
maxDate:datetime2,
startDate:datetime1 ,
endDate:datetime2,
formatTime:'H:i',
formatDate:'d / m / Y',
});
但它不起作用..
代码有什么问题?
(#preDate)。val();
var jsDate = new Date(t);
var time = new Date()。getTime();
var currentdate = new日期(时间);
var datetime1 = - + jsDate.getDate()+/+(jsDate.getMonth()+ 1)+/+ jsDate.getFullYear();
var datetime2 = currentdate.getDate()+/+(currentdate.getMonth()+ 1)+/+ currentdate.getFullYear();
( #myDtPicker)。datetimepicker({
minTime:0,
minDate:datetime1,
maxDate:datetime2,
startDate:datetime1,
endDate:datetime2,
formatTime:'H:i',
formatDate:'d / m / Y',
});
但它不起作用..
代码有什么问题?
你好,
只需更改为此行
minDate:' 0',
maxDate:' + 2M',
minDate:'0'表示,最小日期将是今天日期
和maxDate:+ 2M表示,它是wi从今天起加上2个月的最大日期
JSFIDDLE
I'm using jquery datetime picker.
I want to disable date selection of dates previous to specific date.
for e.g.
if my date is 13/03/2016,
calendar starts from this date and enddate will be current date i.e. 13/05/2016.
user should not be able to select date before 13/03/2016 and after 13/05/2016.
What I have tried:
var t = $("#preDate").val(); var jsDate = new Date(t); var time = new Date().getTime(); var currentdate = new Date(time); var datetime1= "-"+jsDate.getDate()+"/"+(jsDate.getMonth()+1) +"/"+jsDate.getFullYear(); var datetime2 = currentdate.getDate()+"/"+(currentdate.getMonth()+1) +"/"+currentdate.getFullYear(); $("#myDtPicker").datetimepicker({ minTime:0, minDate:datetime1, maxDate:datetime2, startDate:datetime1, endDate:datetime2, formatTime: 'H:i', formatDate: 'd/m/Y', });
but it's not working..
What's wrong with the code?
("#preDate").val(); var jsDate = new Date(t); var time = new Date().getTime(); var currentdate = new Date(time); var datetime1= "-"+jsDate.getDate()+"/"+(jsDate.getMonth()+1) +"/"+jsDate.getFullYear(); var datetime2 = currentdate.getDate()+"/"+(currentdate.getMonth()+1) +"/"+currentdate.getFullYear();
("#myDtPicker").datetimepicker({ minTime:0, minDate:datetime1, maxDate:datetime2, startDate:datetime1, endDate:datetime2, formatTime: 'H:i', formatDate: 'd/m/Y', });
but it's not working..
What's wrong with the code?
Hello,
Simply change to this line
minDate: '0', maxDate: '+2M',
minDate : '0' means , Min date will be today date
and maxDate: +2M means , it will add 2 month with Max date from today date
JSFIDDLE
这篇关于如何在datetimepicker中禁用之前和即将到达特定日期的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!