通过日期获取日期所在年的周数

 1 function theWeek(now) {
 2     var totalDays = 0;
 3     years = now.getYear()
 4     if (years < 1000)
 5         years += 1900
 6     var days = new Array(12);
 7     days[0] = 31;
 8     days[2] = 31;
 9     days[3] = 30;
10     days[4] = 31;
11     days[5] = 30;
12     days[6] = 31;
13     days[7] = 31;
14     days[8] = 30;
15     days[9] = 31;
16     days[10] = 30;
17     days[11] = 31;
18 
19     //判断是否为闰年,针对2月的天数进行计算
20     if (Math.round(now.getYear() / 4) == now.getYear() / 4) {
21         days[1] = 29
22     } else {
23         days[1] = 28
24     }
25 
26     if (now.getMonth() == 0) {
27         totalDays = totalDays + now.getDate();
28     } else {
29         var curMonth = now.getMonth();
30         for (var count = 1; count <= curMonth; count++) {
31             totalDays = totalDays + days[count - 1];
32         }
33         totalDays = totalDays + now.getDate();
34     }
35     //得到第几周
36     var week = Math.round(totalDays / 7);
37     return week;
38 }

 

转载于:https://www.cnblogs.com/lxnv587/p/9372402.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值