在javascript中匹配值的开始或结束日期 [英] match values start or end dates in javascript
问题描述
我在javascript日期方面遇到了问题,我想比较投放日期
比较开始日期或结束日期。
I am facing an issue in javascript dates, i want to match slot dates
comparing start_date or end_date.
我的组件
{this.state.data && this.state.data.length
? this.state.data
.filter(data => {
const date = new Date(data.start_date);
const enddate = new Date(data.end_date);
console.log(date); //start
console.log(enddate); //end
return date > prevDate && date < nextDate;
})
.map(({ cust_full_name, start_date }, index) => (
<div class="row" key={index}>
slot: {index + 1}
<p>{start_date}</p>
<p>{cust_full_name}</p>
</div>
))
: null}
工作演示:
https:// codesandbox .io / s / lucid-dream-gl3l7?file = / src / App。 js
我该怎么办?有人可以帮我吗?
what should i do? can anyone help me?
推荐答案
编辑:您所在状态的广告位值位于数组中,但是当您将其传递给日期时, 't访问字符串值。
Your slot values in your state are in arrays but when you pass them to date you aren't accessing the string value.
slot1:[ date]
不正确:新日期[slot1]
正确:新日期[slot [0]]
slot1 : ["date"]
Incorrect: new Date[slot1]
Correct: new Date[slot[0]]
在您的沙箱中似乎您从来没有在这里填充 newprevious
和 newseconddate
:
In your sandbox it seems you never populated newprevious
and newseconddate
here:
const prevDate = new Date(this.state.newprevious);
const nextDate = new Date(this.state.newseconddate);
一旦我在上面的状态部分中填充了这些内容,它似乎就可以工作了。我也建议将Date变成一个时代。因此数字更易于使用(使用以下方法获取特定日期的纪元Javascript )
Once i populated those in the above state section, it seems to work. I do also suggest maybe turning Date into something like epoch; so the numbers are easier to work with (Get epoch for a specific date using Javascript)
这篇关于在javascript中匹配值的开始或结束日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!