• js获取当前日期一年的第几周


    获取当前日期一年中的第几周

     1     function theWeek() {
     2         var totalDays = 0;
     3         now = new Date();
     4         years = now.getYear()
     5         if (years < 1000)
     6             years += 1900
     7         var days = new Array(12);
     8         days[0] = 31;
     9         days[2] = 31;
    10         days[3] = 30;
    11         days[4] = 31;
    12         days[5] = 30;
    13         days[6] = 31;
    14         days[7] = 31;
    15         days[8] = 30;
    16         days[9] = 31;
    17         days[10] = 30;
    18         days[11] = 31;
    19         //判断是否为闰年,针对2月的天数进行计算
    20         if (Math.round(now.getYear() / 4) == now.getYear() / 4) {
    21             days[1] = 29
    22         } else {
    23             days[1] = 28
    24         }
    25         if (now.getMonth() == 0) {
    26             totalDays = totalDays + now.getDate();
    27         } else {
    28             var curMonth = now.getMonth();
    29             for (var count = 1; count <= curMonth; count++) {
    30                 totalDays = totalDays + days[count - 1];
    31             }
    32             totalDays = totalDays + now.getDate();
    33         }
    34         //得到第几周
    35         var week = Math.round(totalDays / 7);
    36         return week;
    37     }
  • 相关阅读:
    POJ 1905 Expanding Rods 木棍膨胀
    [JSOI2007] 文本生成器
    18.09.22模拟赛T2 历史
    [USACO18OPEN] Talent Show
    [国家集训队] 整数的lqp拆分
    [HNOI2008] GT考试
    读入优化效果测试
    Trie图 模板
    manacher算法 详解+模板
    [洛谷P4299] 首都
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/11633806.html
Copyright © 2020-2023  润新知