Get all months name from year in moment.js

后端 未结 9 958
执笔经年
执笔经年 2020-12-14 07:31

I want to get all months name from year in moment.js

if the year is 2011, then i want to all months name in momentjs

i have tried this below

9条回答
  •  半阙折子戏
    2020-12-14 08:02

    There happens to be a function for that:

    moment.monthsShort()
    // ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
    

    Or the same using manual formatting:

    Array.apply(0, Array(12)).map(function(_,i){return moment().month(i).format('MMM')})
    

    I guess you want to display all names utilizing Moment.js locale data, which is a reasonable approach.

提交回复
热议问题