js常用方法-获取当前月天数数组

方法

/**
     * 应用于图表插件---获取当前月天数数组
     * @param
     * @returns {obj}
     */
    static getChartMonth() {
        let dataTimes = [];
        let date = new Date();
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let d = new Date(year, month, 0);
        let n = +d.getDate();

        for (var i = 1; i < n + 1; i++) {
            dataTimes.push(i + ' 号');
        }

        return dataTimes; //返回天数数组
    }

 

使用

console.log('当前月数组---', this.myUtils.getChartMonth())

 

posted @ 2021-03-11 10:00  老板来斤代码  阅读(453)  评论(0)    收藏  举报