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

后端 未结 11 638
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  长情又很酷
    2020-12-14 08:07

    You could use _.times helper from lodash alongside moment like so:

        var daysInMonth = [];
    
        var monthDate = moment().startOf('month'); // change to a date in the month of interest
    
        _.times(monthDate.daysInMonth(), function (n) {
        	 daysInMonth.push(monthDate.format('DD-ffffd'));  // your format
        	 monthDate.add(1, 'day');
        });
        
        console.log(daysInMonth)
    
    

提交回复
热议问题