nextTuesday
返回给定日期之后的下一个星期二的日期。
javascript
import { addDays, getDay } from "date-fns";
// 示例日期
const date = new Date(); // 当前日期
// 获取下一个星期二的日期
let nextTuesday = date;
while (getDay(nextTuesday) !== 2) {
nextTuesday = addDays(nextTuesday, 1);
}
console.log("下一个星期二的日期:", nextTuesday);
// 下一个星期二的日期:Tue May 14 2024 00:00:00