jsはある年のある月を獲得します.ある日は一年の中で何週目ですか?
795 ワード
/**
*
*
*/
function getWeekNumber(y, m, d) {
var targetDay = newDate(y, m - 1, d);
var year = targetDay.getFullYear();
var month = targetDay.getMonth();
var days = targetDay.getDate();
//
for (var i = 1; i < m; i++) {
days += getMonthDays(year, i);
}
//
var yearFirstDay = newDate(year, 0, 1).getDay();
//
days += yearFirstDay;
var week = Math.ceil(days / 7);
return week;
}
/**
*
*/
function isLeapYear(year) {
return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
/**
*
*/
function getMonthDays(year, month) {
return [31, (isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
}