Napster Napster - 3 years ago 143
Javascript Question

Get months name array in different langualge

In default language (en) works fine.

moment().format('LL'); \\ 25 December 2014
moment.months(); \\ ["January", "February","March","April","May","June","July","August","September","October","November","December"]


Now with different language - (pt-br)

var pt = moment().locale('pt-br');
pt.format('LL'); \\ 25 de dezembro de 2014
pt.months(); \\ 11


pt.months();
- Why not it returns array of month names ?

Is there different method to get month array ?

Answer Source

In your code, the variable pt is an instance of a moment object, representing a specific point in time. The months function of a moment object returns the month number of that instance, 0 through 11.

To get the names of the months, you call the moment.months() function, from the moment global. Setting the language is an independent operation.

moment.locale('pt');
var months = moment.months();

//    ["janeiro", "fevereiro", "março", "abril", "maio", "junho", 
//     "julho", "agosto", "setembro", "outubro", "novembro", "dezembro"] 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download