How to set language globally for moment.js

后端 未结 4 1524
忘了有多久
忘了有多久 2021-01-02 07:21

I get for example: 1day ago. What I need is to set for different language, for example for de. Any suggestion how can I do that?

moment(Date.         


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-02 07:23

    See official docs on how changing locale globally.

    Note that you have to import locale data (e.g. moment-with-locales.min.js)

    Here a working example:

    moment.locale('de');
    console.log(moment(Date.now()).fromNow()); //vor ein paar Sekunden

    You can also use only data for a given locale (e.g. de):

    moment.locale('de');
    console.log(moment(Date.now()).fromNow()); //vor ein paar Sekunden
    
    

    Moreover you are redefining moment in your code, that is incorrect

    var moment = moment();
    

提交回复
热议问题