gpt4 book ai didi

javascript - Moment js 不能在 React Native 中使用 JSON

转载 作者:行者123 更新时间:2023-11-30 13:48:35 26 4
gpt4 key购买 nike

这是我的 JSON:

orders:[{
"buyerEmail": "unknow@gmail.com",
"profile_name_ru": "ПРЕДПРИНИМАТЬ",
"bin": "20940010947",
"date_time": "15.10.2019 10:39:27"
}
]

我正在获取 date_time 并像这样在 React Native 应用程序上输出它。

<View>
<Text>{orders.dateTime}</Text>
</View>

正在显示。但是,如果我使用的是 Moment.js,则会收到无效日期。

render(){   
const ed = (order.dateTime);
const check = moment(new Date(ed)).format("DD.MM.YYYY, HH:MM");
return (
<View>
<Text>{check}</Text>
</View>
)
}

谁能告诉我为什么我得到的日期无效?

最佳答案

Moment 工作正常。但是您的时间字符串是错误的。您需要将日期格式字符串更改为 YYYY-MM-DD 或在 moment 启动时提及格式

MM- month

mm- minutes

hh- 12 hrs

HH- 24 hrs

let str = '15.10.2019 10:39:27';

console.log(new Date(str)) //check this its return null

//so need to mention format while initialize
console.log(moment(str,'DD.MM.YYYY HH:mm:ss').format('DD.MM.YYYY, hh:mm A'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>

关于javascript - Moment js 不能在 React Native 中使用 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58776976/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com