How to set language globally for moment.js

后端 未结 4 1522
忘了有多久
忘了有多久 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:47

    To build onto the answer by Gapur, how I got it to work (React native) was like this,

    ... other imports
    import moment from "moment";
    import russianLocale from "moment/locale/ru";
    import englishLocale from "moment/locale/en-gb";
    import chineseLocale from "moment/locale/zh-cn";
    
    const Component = ({ ...props, language }) => {
      moment.locale(language);
    
    ... logic
    
    // wherever 'moment' is used, it's displayed in 
    // the language that is indicated by the language prop
    
    ... other logic
    

    moment version 2.24.0

提交回复
热议问题