This is what I have but it does not work.
import moment from 'moment'
import 'moment/min/moment-with-locales'
import 'moment-duration-format' // used by moment
componentDidMount () {
console.log(moment.locale())
console.log(moment.locale('zh-cn'))
console.log(moment.locale())
}
console log outputs: en, en, en
expected console log output: en, zh-cn, zh-cn
When I tried changing import moment from 'moment' to import moment from 'moment/min/moment-with-locales' but it throws an error on this line:
const total = moment.duration(this.props.stoveUsage.total, 'seconds').format('H:mm', { trim: false })
error: momentWithLocales2.default.duration(...).format is not a function
All you need to do is to import the locale you want to use. In my example, I wanted to make sure all the dates were in Spanish and this is what I did:
import moment from 'moment';
import 'moment/locale/es';
Then whenever you need it just do:
moment.locale('es')
moment(date).format("DD - MMMM - YYYY"
The output will be:
19 - julio - 2018
I guess you will have to import as many locales as you need in your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With