【发布时间】:2020-05-10 21:07:27
【问题描述】:
我遇到了关于 javascript 日期的问题。我想比较start date and end date JSON 数据并显示在特定插槽newprevious, newcurrent, newfirstdate and newseconddate
反应组件
我试过了,但我的情况不行
<div class="row">
{this.state.data && this.state.data.length
? // this.state.data[index].start_date.toString() > this.state.newprevious
// this.state.data[index].start_date.toString() > this.state.newcurrent
// this.state.data[index].start_date.toString() > this.state.newfirstdate
// this.state.data[index].start_date.toString() > this.state.newseconddate
this.state.data.map(
({ cust_full_name, full_name, start_date }, index) => (
<div class="row" key={index}>
slot: {index + 1}
<p>{start_date}</p>
<p>{cust_full_name}</p>
</div>
我的工作演示:
https://codesandbox.io/s/priceless-bird-ue3iu?file=/src/App.js
我的代码输出:
只需匹配 start date and end date JSON 数据并显示在特定的 previous , current , first and second date 插槽中
预期输出:
我该怎么办?请帮帮我?
【问题讨论】:
-
小心建议将字符串转换为日期的答案。 “2020-05-11 01:45:50”不是 ECMA-262 支持的格式,因此解析取决于实现,至少一个当前浏览器会将其解析为无效日期。见Why does Date.parse give incorrect results?
标签: javascript reactjs date datetime match