How do I change the language of moment.js?

前端 未结 20 1506
别那么骄傲
别那么骄傲 2020-11-29 16:27

I am trying to change the language of the date which is being set by moment.js. The default one is English, but I want to set the German language. These is what I tried:

20条回答
  •  隐瞒了意图╮
    2020-11-29 16:54

    FOR METEOR USERS:

    moment locales are not installed by default in meteor, you only get the 'en' locale with the default installation.

    So you use the code as shown correctly in other answers:

    moment.locale('it').format('LLL');
    

    but it will remain in english until you install the locale you need.

    There is a nice, clean way of adding individual locales for moment in meteor (supplied by rzymek).

    Install the moment package in the usual meteor way with:

    meteor add rzymek:moment
    

    Then just add the locales that you need, e.g. for italian:

    meteor add rzymek:moment-locale-it
    

    Or if you really want to add all available locales (adds about 30k to your page):

    meteor add rzymek:moment-locales
    

提交回复
热议问题