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

后端 未结 11 616
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  -上瘾入骨i
    2020-12-14 08:01

    Alternatively you might now use moment range to achieve this :

    const month = moment('2012-02', 'YYYY-MM');
    const range = moment().range(moment(month).startOf('month'), moment(month).endOf('month'));
    const days = range.by('days');
    
    console.log([...days].map(date => date.format('DD-ffffd')));
    

提交回复
热议问题