一:解法流程:
(按照获取下周2的例子来)
1.获取当前时间
2.获取今天的0点时间
3.根据一周7天 减去当前周几 加上 要的下周2 计算出下周2距离今天的天数
4.一天86400000毫秒 计算出距离天数的毫秒数 加上今天0点的毫秒 获得 下周2的时间
5.根据获取到的下周2时间 获取到对应的年月日
getNextWeekdayDate(weekday) {
const d = new Date();
const today = new Date(`${d.getFullYear()}/${d.getMonth() + 1}/${d.getDate()} 00:00:00`);
let cday = 7 - today.getDay() + Number(weekday)
const targetDate = new Date(today.getTime() + (cday * 86400000));
const month = targetDate.getMonth() + 1;
const date = targetDate.getDate();
return `${targetDate.getFullYear()}年${month}月${date}日`;
}
weekday为你要想要下周 周几 (weekday: 1|2|3|4|5|6|7})
调用获取对应的年月日
this.getNextWeekdayDate(2)
ios 手机 年月日 记得用 / 拼接
完美解决!