Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  153] [ 5]  / answers: 1 / hits: 83330  / 9 Years ago, fri, march 27, 2015, 12:00:00

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 code, but it's not working for me.



var xxx = moment().months(2011);


Showing result is



enter



also i have tried xxx.months(), but it's return result is 7



but i want jan,feb,mar,......dec. hmm What can i do?


More From » momentjs

 Answers
9

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.


[#67284] Wednesday, March 25, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
juancarlos

Total Points: 580
Total Questions: 105
Total Answers: 103

Location: Grenada
Member since Sun, Dec 20, 2020
4 Years ago
juancarlos questions
Wed, Mar 24, 21, 00:00, 3 Years ago
Wed, Jul 15, 20, 00:00, 4 Years ago
Wed, Jan 8, 20, 00:00, 5 Years ago
Mon, May 20, 19, 00:00, 5 Years ago
;