JS怎么获取系统时间上一个月份的天数

获取上一个月时间天数的数字,1,2,3,4,5,6......如此排列
2025-04-30 23:48:20
推荐回答(1个)
回答1:

var getLastDays = function(){
    var now = new Date;
    now.setMonth(now.getMonth() - 1);
    now.setDate(1);
    var next = new Date;
    next.setDate(1);
    var arr = [];
    while(now < next){
        arr.push(now.getDate());
        now.setDate(now.getDate() + 1);
    }
    return arr;
}

console.log(getLastDays());