vue 得到当月的天数getDate()方法

getDate()
today.getMonth() + 1,加 1 得到当前月份
new Date(today.getFullYear(), today.getMonth(), 0);
得到当前的年份,月份,0代表 today.getMonth()月1号的前一天。
date = new Date(2017,11,0);//表示date是2017/12/1号的前一天,就是2017/11/30这天
通常用new Date(2020,2,0).getDate()计算某月的天数

 var today = new Date();
// 获取当月天数 curretMonthDayCount
 var curretMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0);
 var curretMonthDayCount = curretMonth.getDate();
// 获取上个月天数 preMonthDayCount
 var preMonth = new Date(today.getFullYear(), today.getMonth(), 0);
 var preMonthDayCount = preMonth.getDate();
// 获取前一个月天数
 var beforePreMonth = new Date(today.getFullYear(), today.getMonth() - 1, 0);
 var beforePreMonthDayCount = beforePreMonth.getDate();
Logo

前往低代码交流专区

更多推荐