1 回答
TA贡献1802条经验 获得超10个赞
尝试这个
const moment = require('moment');
const databases = [
{
name: 'Mark',
time: [
{
"date": "2020-04-23T00:14:03.217Z",
"nature": "In",
},
{
"date": "2020-04-23T15:14:03.217Z",
"nature": "Out",
},
{
"date": "2020-04-24T00:14:03.217Z",
"nature": "In",
},
{
"date": "2020-04-24T15:14:03.217Z",
"nature": "Out",
},
{
"date": "2020-04-25T00:14:03.217Z",
"nature": "In",
},
{
"date": "2020-04-25T15:14:03.217Z",
"nature": "Out",
},
{
"date": "2020-04-26T08:14:03.217Z",
"nature": "In",
},
{
"date": "2020-04-26T15:14:03.217Z",
"nature": "Out",
}]
},
{
name: 'David',
time: [
{
"date": "2020-04-23T08:14:03.217Z",
"nature": "In",
},
{
"date": "2020-04-23T15:14:03.217Z",
"nature": "Out",
},
{
"date": "2020-04-24T10:14:03.217Z",
"nature": "In",
},
{
"date": "2020-04-24T15:14:03.217Z",
"nature": "Out",
},
{
"date": "2020-04-26T10:14:03.217Z",
"nature": "In",
},
{
"date": "2020-04-26T15:14:03.217Z",
"nature": "Out",
},
{
"date": "2020-04-27T10:10:03.217Z",
"nature": "In",
},
{
"date": "2020-04-27T15:14:03.217Z",
"nature": "Out",
}
]
}
]
const databases1 = databases.map((t) => {
const time = t.time.filter(d => {
return moment(d.date).isBetween(moment('2020-04-24T16:00:00.000Z'), moment('2020-04-25T16:00:00.000Z'))
});
return { ...t, time };
})
console.log(JSON.stringify(databases1));
添加回答
举报