javascript獲取當(dāng)前日期所屬第幾周函數(shù),具體代碼如下:
////////////////////////////////////////////////////////////////////////////////////////////////////
//獲取當(dāng)前日期在當(dāng)前年第幾周函數(shù)封裝,例如2013-08-15 是當(dāng)前年的第32周
////////////////////////////////////////////////////////////////////////////////////////////////////
function theWeek() {
var totalDays = 0;
now = new Date();
years = now.getYear()
if (years < 1000)
years += 1900
var days = new Array(12);
days[0] = 31;
days[2] = 31;
days[3] = 30;
days[4] = 31;
days[5] = 30;
days[6] = 31;
days[7] = 31;
days[8] = 30;
days[9] = 31;
days[10] = 30;
days[11] = 31;
//判斷是否為閏年,針對2月的天數(shù)進(jìn)行計(jì)算
if (Math.round(now.getYear() / 4) == now.getYear() / 4) {
days[1] = 29
} else {
days[1] = 28
}
if (now.getMonth() == 0) {
totalDays = totalDays + now.getDate();
} else {
var curMonth = now.getMonth();
for (var count = 1; count <= curMonth; count++) {
totalDays = totalDays + days[count - 1];
}
totalDays = totalDays + now.getDate();
}
//得到第幾周
var week = Math.round(totalDays / 7);
return week;
}
更多信息請查看IT技術(shù)專欄