【问题标题】:How to change format Date react-native如何更改格式日期反应本机
【发布时间】:2021-01-07 11:57:35
【问题描述】:

我想更改 DD/MM/YYYY 中的格式日期,HH:MM 如果有人知道吗?我的代码:

class Dashboard extends Component {
  constructor(props) {
    super(props);
    this.state = {
      sport: {
        clubs: [],
      },
      rival: {
        clubs: [],
      },
      dateMatch: '',
      DB: {sound: []},
    };
  }

在这里打电话

          <Text
            style={{
              textAlign: 'center',
              marginTop: 30,
              fontSize: 18,
              backgroundColor: 'rgba (209,209,209, .4)',
            }}>
            le {element.dateMatch}
          </Text>

感谢收看!

【问题讨论】:

标签: javascript react-native


【解决方案1】:

您可以轻松地使用 momentjs

要在您的项目上安装 moment 运行此命令

npm install moment --save

然后你可以在你的代码中导入它

import moment from 'moment';

对于日期转换,使用下面的示例控制台日志

console.log( moment('2018-01-01 13:40:39').format('MM-DD-YYYY hh:mm a') );

只需在瞬间传递您的日期值

【讨论】:

  • 完美它的工作原理,你有想法有法语的时间格式吗?
猜你喜欢
  • 2021-07-26
  • 2022-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-28
  • 2019-03-31
相关资源
最近更新 更多