Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moment.js - I can't change the date to "pt-br" (ReactJS)

I'm making a calendar in Portuguese on ReactJS.

Despite being something simple, I'm not able to change my library date "moment.js" to be in the portuguese language (brazil).

Already tried code:

<strong>{moment(currentDate).locale('pt-br').format('LLLL')}</strong>

But I don't work, it keeps bringing the date in English.

1: Date in English

This is the date format code:

const [currentDate, setCurrentDate] = useState(new Date())

<Col>
 <strong>{moment(currentDate).format('LLLL')}</strong>
</Col>

How do I make the date stay in Portuguese(Brazil)?

like image 339
Sergio Luis Sá Avatar asked Nov 01 '25 15:11

Sergio Luis Sá


2 Answers

I just decided to import the location:

import 'moment/locale/pt-br'

and add code:

moment.locale('pt-br')
like image 188
Sergio Luis Sá Avatar answered Nov 04 '25 03:11

Sergio Luis Sá


I have tried to use 'pt-br' like this:

import 'moment/locale/pt-br'
import moment from 'moment'

and it was not working in a React project with Typescript.

I got to fix it this way:

import 'moment/dist/locale/pt-br'

Just add the folder 'dist' while you're importing the language. I hope everything works accordingly.

like image 21
PAULO RAPHAEL PESSOA DE MELLO Avatar answered Nov 04 '25 04:11

PAULO RAPHAEL PESSOA DE MELLO



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!