js获取当前日期是一年的第几周
getWeekOnYears(val) { const year = dayjs(val).year() //获取年 const month = dayjs(val).month() + 1 //获取月 const day = dayjs(val).date() //获取天 const isLeapYear = (year % 400 === 0) || (year % 4 === 0 && year % 100 !== 0) //判断是否为闰年 const second = isLeapYear ? 29 : 28 const monthList = [31, second, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].splice(0, month - 1) //获取月份数组 let currentDays; //当前日期天数 let currentWeek; //当前周数 //计算天数 currentDays = month === 1 ? day : (monthList.reduce((t, v) => { return t + v }, 0)) + day //计算是第几周 currentWeek = currentDays % 7 === 0 ? currentDays / 7 : Math.ceil(currentDays / 7) return currentWeek },