js获取最近的周末或某天

2023-05-17  本文已影响0人  hui树

// 周末 查最近的周末

                var date6 = new Date();
                while (date6.getDay() !== 6) date6.setDate(date6.getDate() - 1);
                console.log('date6 ')
                var date7 = new Date();
                while (date7.getDay() !== 0) date7.setDate(date7.getDate() - 1);
                console.log('date7 ')

getDay() 方法可返回一周(0~6)的某一天的数字。注意: 星期天为 0, 星期一为 1, 以此类推。


image.png

参考https://www.coder.work/article/5418679

上一篇 下一篇

猜你喜欢

热点阅读