2014-12-25 33 views
0

默認語言(en)正常工作。在不同的langualge中獲取月份名稱數組

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

現在 - (PT-BR)

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

pt.months(); - 爲什麼不返回月份名稱的數組?

有沒有不同的方法來獲取月份數組?

+0

您的語言環境是否首先定義月份名稱? (如http://momentjs.com/docs/#/customization/month-names/中所述) – CBroe

+0

我已經加入了「moment-with-locales.min.js」。那麼我是否需要定義月份名稱? – Napster

回答

1

在您的代碼中,變量pt是時刻對象的實例,代表特定的時間點。片刻對象的months函數返回該實例的月份數,0至11

要得到個月的名字,你叫moment.months()功能,從目前全球。設置語言是一項獨立的操作。

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

// ["janeiro", "fevereiro", "março", "abril", "maio", "junho", 
//  "julho", "agosto", "setembro", "outubro", "novembro", "dezembro"]