首页 > 解决方案 > 如何在js Fullcalender中找到第2个和第4个星期六?

问题描述

如何在 JavaScript fullcalender api 中找到第二个和第四个星期六,以便我可以用“week Day Off”事件名称突出显示那些第 2 个和第 4 个星期六?

Fullcalendar_screenshot在此处输入图像描述

标签: javascriptfullcalendar

解决方案


您需要找到当月的所有星期六。然后按奇数索引过滤,因为第 2 和第 4 是13索引。

现在您可以突出显示匹配的日期。

function getSaturdays(year, month) {

            let day, date;
            let saturdays = [];
            day = 1;
            date = new Date(year, month, day);
            while (date.getMonth() === month) {
                if (date.getDay() === 6) { // Sun=0, Mon=1, Tue=2, etc.
                    saturdays.push(new Date(year, month, day).getDate());
                }
                day += 1;
                date = new Date(year, month, day);
            }
            return saturdays;
        }

        let saturdays = getSaturdays(2021, 5).filter((day, index) => index % 2 !== 0)
        console.log(saturdays)

原始答案


推荐阅读