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     }
posted @ 2019-10-08 09:58  陈彦斌  阅读(3525)  评论(0编辑  收藏  举报