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:
Then whenever you need it just do:
The output will be:
I guess you will have to import as many locales as you need in your application.