jsは現在の日付を取得して、一年の第何週目ですか?
5900 ワード
現在の日付を取得してから1年目の何週目になりますか?
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 }