gpt4 book ai didi

javascript - FlatPickr - 获取日历日期范围内的星期日(含)

转载 作者:行者123 更新时间:2023-12-01 04:33:16 26 4
gpt4 key购买 nike

我正在使用 flatPickr(日历插件)来完成此任务。我将 minDate 和 maxDate(始终是星期日)从 PHP 函数发送到 JavaScript:

$("#weeklySelector").flatpickr(
{
inline: true,
enableTime: false,
dateFormat: "Y-m-d",
minDate: "<?php echo getSecondSunday($oldestDay[0], $newestDay[0]); ?>",
maxDate: "<?php echo getLastSunday($newestDay[0], getSecondSunday($oldestDay[0], $newestDay[0])); ?>",
defaultDate: "<?php echo getLastSunday($newestDay[0], getSecondSunday($oldestDay[0], $newestDay[0])); ?>",
enable: [
function(date) {
// Enable only the Sundays between the minDate and maxDate
// Include the minDate & maxDate because they both always will be Sundays

}
],
onChange: function(selectedDates, dateStr, instance) {
weeklyDate = dateStr;
},
});

在伪代码中,逻辑如下所示:

// minDate = "2020-04-05";
// maxDate = "2020-04-26";
enable: [
function(date) {
minDate, while(minDate+7 <= maxDate);
// Output: "2020-04-05", "2020-04-12", "2020-04-19", "2020-04-26"
}
],

文档链接:https://flatpickr.js.org/examples/#disabling-all-dates-except-select-few

最佳答案

您需要使用.getDay()日期方法,返回星期几(0 是星期日)。

    enable:[ 
function(date) {
return date.getDay() === 0; // 0 is sunday
}
]

关于javascript - FlatPickr - 获取日历日期范围内的星期日(含),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61014035/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com