javascript - 如何在js Fullcalender中找到第2个和第4个星期六?
问题描述
如何在 JavaScript fullcalender api 中找到第二个和第四个星期六,以便我可以用“week Day Off”事件名称突出显示那些第 2 个和第 4 个星期六?
解决方案
您需要找到当月的所有星期六。然后按奇数索引过滤,因为第 2 和第 4 是1
和3
索引。
现在您可以突出显示匹配的日期。
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)
推荐阅读
- amazon-web-services - Helm 升级引发 YAML 解析器错误
- java - 通过使用 . 和
- reactjs - React Logo 更改不适用于带有本地 href 的链接
- javascript - 每次用户刷新时,聊天都会显示用户断开连接
- python-3.x - 用于抓取文章的报纸 api
- php - 使用 php/pdo 连接到远程 wpengine mysql 服务
- python - 在某些情况下,将 collections.namedtuple 与 ProcessPoolExecutor 一起使用会卡住
- java - 这个 JoinForkTask 问题有解决方案吗?
- html - 在css上选择具有属性的不同div
- java - 为什么我的 Springboot 主方法在代码中只调用一次时启动 2 个线程?