代码中使用了 Day.js 连接: https://www.cnblogs.com/cjrfan/p/9154539.html
val = ['2021-07-26', '2021-07-30']
const olddate = new Date(val[0]).getDay() === 0 ? 7 : new Date(val[0]).getDay()
const newdate = new Date(val[1]).getDay() === 0 ? 7 : new Date(val[1]).getDay()
const interval = newdate - olddate
console.log('时间1', val[0])
console.log('时间2', val[1])
console.log('时间1->是周几', olddate)
console.log('时间2->是周几', newdate)
console.log('周->间隔', interval)
console.log('日期间隔', window.dayjs(val[1]).diff(window.dayjs(val[0]), 'day'))
if (interval === window.dayjs(val[1]).diff(window.dayjs(val[0]), 'day')) {
console.log('同一周')
} else {
console.error('不是同一周')
}
打印结果 请各位大佬指教
|