两天后截止时间
Cut-off time two days later
在 Datepicker 中,我试图将可选日期限制为星期日,并且仅在星期四 15:00 之前选择。
我做错了什么?,仅限星期日有效,截止时间 15:00 有效,但前一天不是两天前。
$( "#deliverysunday" ).datepicker({
dateFormat: "yy-mm-dd",
showWeek: true,
firstDay: 1,
beforeShowDay: function(date){ return [date.getDay() == 0,""]},
minDate: new Date().getHours() >= 15 ? 2 : 0
});
如果我对您的问题的理解正确,您希望确保选择的最早日期是不晚于星期四 15:00 的第一个星期日。
minDate
选项将控制哪个日期是最早的可选日期;确定截止时间的逻辑应该在您的 beforeShowDay
选项中:
$( "#deliverysunday" ).datepicker({
dateFormat: "yy-mm-dd",
showWeek: true,
firstDay: 1,
beforeShowDay: function(date) {
return [isDateSelectable(date)];
},
minDate: 2
});
/**
* Given a date, returns a boolean to indicate
* whether the date should be selectable in a picker.
* Tests the date according to the rules:
*
* - Is the date a Sunday?
* - Is it currently before the cutoff time?
*/
function isDateSelectable(date) {
// Cutoff interval = Sun@00:00 - Thu@15:00 = 57 hours
var intervalInMillis = 57 * 60 * 60 * 1000;
var now = new Date();
var isPriorToInterval = now.getTime() < date.getTime() - intervalInMillis;
// Is date a Sunday?
var isSunday = date.getDay() === 0;
return isSunday && isPriorToInterval;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<h1>Date picker example</h1>
<div id="deliverysunday"></div>
在 Datepicker 中,我试图将可选日期限制为星期日,并且仅在星期四 15:00 之前选择。 我做错了什么?,仅限星期日有效,截止时间 15:00 有效,但前一天不是两天前。
$( "#deliverysunday" ).datepicker({
dateFormat: "yy-mm-dd",
showWeek: true,
firstDay: 1,
beforeShowDay: function(date){ return [date.getDay() == 0,""]},
minDate: new Date().getHours() >= 15 ? 2 : 0
});
如果我对您的问题的理解正确,您希望确保选择的最早日期是不晚于星期四 15:00 的第一个星期日。
minDate
选项将控制哪个日期是最早的可选日期;确定截止时间的逻辑应该在您的 beforeShowDay
选项中:
$( "#deliverysunday" ).datepicker({
dateFormat: "yy-mm-dd",
showWeek: true,
firstDay: 1,
beforeShowDay: function(date) {
return [isDateSelectable(date)];
},
minDate: 2
});
/**
* Given a date, returns a boolean to indicate
* whether the date should be selectable in a picker.
* Tests the date according to the rules:
*
* - Is the date a Sunday?
* - Is it currently before the cutoff time?
*/
function isDateSelectable(date) {
// Cutoff interval = Sun@00:00 - Thu@15:00 = 57 hours
var intervalInMillis = 57 * 60 * 60 * 1000;
var now = new Date();
var isPriorToInterval = now.getTime() < date.getTime() - intervalInMillis;
// Is date a Sunday?
var isSunday = date.getDay() === 0;
return isSunday && isPriorToInterval;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<h1>Date picker example</h1>
<div id="deliverysunday"></div>