Jquery根据年份和月份获取本月的开始/结束时间
//获得本月的开始日期
month.getMonthStartDate = function () { var monthStartDate = new Date(nowyear, months, 1); return formatDate(monthStartDate);//返回当月第一天 } //获得本月的结束日期 month.getMonthEndDate = function (nowyear,months) { var days= getMonthDays(months);//获取当月总共有多少天 var monthEndDate = new Date(nowyear,months, days); return formatDate(monthEndDate);//返回当月结束时间 }
---------------------------------------以下是调用的方法--------------------------------
//格式化日期 function formatDate(date) { var myyear = date.getFullYear(); var mymonth = date.getMonth() + 1; var myweekday = date.getDate(); if (mymonth < 10)
{ mymonth = "0" + mymonth; } if (myweekday < 10)
{ myweekday = "0" + myweekday; } return (myyear + "-" + mymonth + "-" + myweekday); } //获得某月的天数 function getMonthDays(nowyear,myMonth) { var monthStartDate = new Date(nowyear, myMonth, 1); var monthEndDate = new Date(nowyear, myMonth + 1, 1); var days = (monthEndDate - monthStartDate) / (1000 * 60 * 60 * 24);//格式转换 return days; }