How to get list of days in a month with Moment.js

后端 未结 11 620
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-14 07:17

Using Moment.js I would like to get all days in a month of specific year in an array. For example:

January-2014:
[
\"01-wed\",
\"02-thr\",
\"03-fri\",
\"04-s         


        
11条回答
  •  Happy的楠姐
    2020-12-14 07:54

    function getAllDatesOfMonth(date) {
        const mDate = moment(date, "YYYY-MM");
        const daysCount = mDate.daysInMonth();
        return Array(daysCount).fill(null).map((v,index)=>{
            const addDays = index === 0 ? 0 : 1;
            return mDate.add(addDays, 'days').format('YYYY-MM-DD');
        });
    }
    

提交回复
热议问题