首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react native moment updateLocal fr crush android

react native moment updateLocal fr crush android
EN

Stack Overflow用户
提问于 2020-01-29 21:29:32
回答 1查看 146关注 0票数 0

我想用moment库把日期翻译成法语。

我创建了一个android构建,但当我打开组件时,它崩溃了。

我的代码是:

代码语言:javascript
复制
import Moment from 'moment';

// i fixed the error 
// var moment = require('moment');
//require('moment/locale/fr');
//moment.locale('fr');



    render() {
....
{
this.state.notifications.map((notification, i) => (     
    Moment.updateLocale('fr', {
        // the config here
        // translate to french
    }),
    notification.type === 'Partage de contact' ?
        <ListItem
            key={i}
            ...
            subtitle={`Date : ${Moment(notification.date).format('dddd D MMMM,  YYYY')}`}
            bottomDivider
        />
        :
        <ListItem
            ...
            subtitle={`Date : ${Moment(notification.date).format('dddd D MMMM,  YYYY')}`}
            bottomDivider
        />
))
}
...

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-29 21:47:58

使用moment.local()将日期转换为任何(法语)语言

代码语言:javascript
复制
import moment from 'moment';


render() {

  var march = moment('2017-03')

  console.log(march.format('MMMM')) 

  moment.locale('fr') // you can set here 

  console.log(march.format('MMMM'))

  ................

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59968152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档