Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moment.js doesn't change locale

I have React Project and I use moment.js for work with date. I tried to change language/locale with official documentation, nothing helped, here's my code:

const moment = require('moment');

class Calendar extends Component {
  render() {
    const variable = moment();
    console.log(variable.locale('ru').format('dddd')) // Thursday
    console.log(moment.locale('ru')); // en
    return (
      <div className="calendar-container">
        Calendar
      </div>
    );
  }
}

Also I tried import '../../node_modules/moment/src/locale/ru.js' did't work either(Error: Cannot find module "./locale"). Any idea how fix this?

like image 491
Ramazan Chasygov Avatar asked Dec 28 '17 18:12

Ramazan Chasygov


1 Answers

Try adding:

import 'moment/locale/ru';

and using:

moment.locale('ru');

To set the locale.

like image 200
acdcjunior Avatar answered Oct 13 '22 21:10

acdcjunior