/**
* 判断年份是否为润年
*
* @param {Number} year
*/
function isLeapYear(year) {
return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
/**
* 获取某一年份的某一月份的天数
*
* @param {Number} year
* @param {Number} month
*/
function getMonthDays(year, month) {
return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month] || (isLeapYear(year) ? 29 : 28);
} /**
* 获取某年的某天是第几周
* @param {Number} y
* @param {Number} m
* @param {Number} d
* @returns {Number}
*/
function getWeekNumber(now) {
year = now.getFullYear(),
month = now.getMonth(),
days = now.getDate();
//那一天是那一年中的第多少天
for (var i = 0; i < month; i++) {
days += getMonthDays(year, i);
}
//那一年第一天是星期几
var yearFirstDay = new Date(year, 0, 1).getDay() || 7;
var week = null;
if (yearFirstDay == 1) {
week = Math.ceil(days / yearFirstDay);
} else {
days -= (7 - yearFirstDay + 1);
week = Math.ceil(days / 7) + 1;
}
return week;
}
//一个月有多少天
function getCountDays(curDate) {
/* 获取当前月份 */
var curMonth = curDate.getMonth();
/* 生成实际的月份: 由于curMonth会比实际月份小1, 故需加1 */
curDate.setMonth(curMonth + 1);
/* 将日期设置为0, 这里为什么要这样设置, 我不知道原因, 这是从网上学来的 */
curDate.setDate(0);
/* 返回当月的天数 */
return curDate.getDate();
}
function getWeekStart(curDate) {
var curMonth = curDate.getMonth();
curDate.setDate(curDate.getDate() + 1 - curDate.getDay());//
return curDate;
}
function getWeekEnd(curDate) {
curDate.setDate(curDate.getDate() + 7 - curDate.getDay());
return curDate;
}
NetAnalyzer下载地址
NetAnalzyer交流群:39753670 (PS 只提供交流平台,群主基本不说话^_^)
[转载请保留作者信息 作者:冯天文 ]