1瞄摊、獲取指定年指定月的天數(shù)
function mGetDate(year, month){
var d = new Date(year, month, 0);
return d.getDate();
}
var totalDay = mGetDate(2004,2); // 29
2、獲取當(dāng)前月的天數(shù)
function mGetDate(){
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth()+1;
var d = new Date(year, month, 0);
return d.getDate();
}
3财骨、獲取當(dāng)前月的所有日期
// 格式化日期
function formatDate(date) {
date = new Date(date);
let myyear = date.getFullYear();
let mymonth = date.getMonth()+1;
let myweekday = date.getDate();
mymonth<10 ? mymonth = "0" + mymonth : mymonth;
myweekday<10 ? myweekday = "0" + myweekday : myweekday;
return `${myyear}-${mymonth}-${myweekday}`;
}
// 獲取當(dāng)前月的天數(shù)
function mGetDate(){
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth()+1;
var d = new Date(year, month, 0);
return d.getDate();
}
// 獲取當(dāng)前月的所有日期
let now = new Date();
let current_month_num = mGetDate();
let current_month = [];
for (let i = 1;i<=current_month_num;i++){
let day = now.setDate(i);
let everyDay = formatDate(day);
current_month.push(everyDay);
}