function getYearMonthDay(){
var nowDays = new Date();
var year = nowDays.getFullYear(); //年
var month = nowDays.getMonth()+1 //月
var day = nowDays.getDate() < 10 ? '0' + nowDays.getDate() : nowDays.getDate();
//判断月份是否为个位
if(month <10){
month = '0' + month;
const startTime = year + '-' + month + '-01' ;
const endTime = year + month + day
return {
startTime:startTime;
endTime:endTime;
}
}
}
方法中进行调用:const currentTime = getYearMonthDay();