How do I change the language of moment.js?

前端 未结 20 1536
别那么骄傲
别那么骄傲 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 17:18

    For me, there are some changes to make(ver. 2.20)

    1. You set locale with moment.locale('de'), and you create a new object representing the date of now by moment() (note the parenthesis) and then format('LLL') it. The parenthesis is important.

    So that means:

    moment.locale('de');
    var now = moment();
    now.format('LLL');
    
    1. Also, remember to use moment-with-locale.js. The file contains all locale info and has a larger file size. Download the locale folder is not enough. If necessary, change the name to be moment.js. Django just refuses to load moment-with-locale.js in my case.

    EDIT: It turned out that renaming the file is not necessary. I just forgot to invoke it in the page so Django does not think loading it is necessary, so my fault.

提交回复
热议问题