function getWeekNumber(date) {
            // 创建表示周日的新 Date 对象并获取其时间戳
            const sunday = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay());
            const sundayTimestamp = sunday.getTime();
            // 计算到本周六的时间跨度并转换为天数
            const saturdayTimespan = 6 * 24 * 3600 * 1000; // 6天的时间跨度
            const saturdayTimestamp = sundayTimestamp + saturdayTimespan;
            const daysSinceStartOfYear = Math.floor((saturdayTimestamp - new Date(date.getFullYear(), 0, 1).getTime()) / (24 * 3600 * 1000));
            // 计算本周在一年中的周数
            const weekNumber = Math.ceil(daysSinceStartOfYear / 7);
            console.log(weekNumber)
            return weekNumber;
        }
        // 示例用法
        const myDate = new Date(2023, 0, 2); // 周日    ***注意:月分是从0开始的{0-11}  对应月份是--{1-12}*****
        const weekNumber = getWeekNumber(myDate); // weekNumber 等于 16

凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数凑凑字数

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。