js Get all the dates of a month based on the current date or month

Use it often, record it

currentMonthDays(){
    let me = this;
    // get standard time
    let date = new Date(me.task.starttime);
    // Get today's date
    let currentDay = date.getDate();
    // Get the current month (the actual month needs to be increased by 1)
    let currentMonth = date.getMonth() + 1;
    //When less than 10->01,02,03...
    if(currentMonth<10){
        currentMonth='0'+currentMonth;
    }
    // get the current year
    let currentYear = date.getFullYear();
    // Get the number of days in the current month
    let currentMonthDays = new Date(currentYear, currentMonth, 0).getDate();
    // Collection of all dates in the current month
    let currentMonthArr = [];
    for (let day = 1; day <= currentMonthDays; day++) {
        // year month day (yyyy-MM-dd)
        let dateItem = currentYear + "-" + currentMonth + "-" + (day < 10 ? '0' + day : day);
        currentMonthArr.push(dateItem);
    }
    me.dates=currentMonthArr;
    return me.dates;
},

Guess you like

Origin blog.csdn.net/Humor_L/article/details/125447020