美文网首页
js获取今天是当年的第几周

js获取今天是当年的第几周

作者: 程序并非猿 | 来源:发表于2022-06-15 14:27 被阅读0次
    function curWeek(){
        const today = new Date();
        let firstDayOfYear = new Date(today.getFullYear(), 0, 1);
        const dayOfWeek = firstDayOfYear.getDay();
        let spendDay = 1;
        if (dayOfWeek != 0) {
          spendDay = 7 - dayOfWeek + 1;
        }
        firstDayOfYear = new Date(today.getFullYear(), 0, spendDay);
        const d = Math.ceil((today.valueOf() - firstDayOfYear.valueOf()) / 86400000);
        return Math.ceil(d / 7);
    }
    

    相关文章

      网友评论

          本文标题:js获取今天是当年的第几周

          本文链接:https://www.haomeiwen.com/subject/iejxvrtx.html