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 }