搜索 |
function getCountDays(date) {
var curDate = new Date(date);
/* 获取当前月份 */
var curMonth = curDate.getMonth();
/* 生成实际的月份: 由于curMonth会比实际月份小1, 故需加1 */
curDate.setMonth(curMonth + 1);
/* 将日期设置为0, 上面一步骤设置了+1,设置以后在读取实际上读取的已经是后一个月的月份了,
设置日期为0其实就是返回上个月的最后一天,利用此也可以求向前或者向几天的某个日期 */
curDate.setDate(0);
/* 返回当月的天数 */
return curDate.getDate();
}
getCountDays(2018/03/01);//01为了兼容IE