【发布时间】:2021-01-21 07:13:37
【问题描述】:
我已经创建了基本的 React 待办事项列表并将其保存到我的数据库中。我设置了dueDatetime 查询它设置时间的位置。我想在具有多个数组的一个对象中查询该时间。像这样:
{
“overdue”: [],
“today”: [],
“tomorrow”: [],
rest of the upcoming dates
}
我想根据日期显示任务编号。我真的不知道从哪里开始。我不想为此使用任何软件包。如果有人帮助我,我会非常高兴。我在codesandbox 分享我的代码。
这是我的前端代码。 PS: Basically I did not anything. because i don't know where to start
import React from "react";
import "./styles.css";
import date from "./Date.json";
import styled from "styled-components";
export default function App() {
const signledate = date?.data?.map((i) => {
return new Date(i.dueDatetime);
});
// console.log(signledate);
const datadate = date?.data?.slice(0, 1)?.map((i) => {
return i.dueDatetime;
});
console.log(signledate);
console.log(new Date());
return (
<Container>
<Card>
<Text>You have 10 overdue</Text>
</Card>
<Card>
<Text>Today you have 6 tasks</Text>
</Card>
<Card>
<Text>Tomorrow you have 20 tasks</Text>
</Card>
<Card>
<Text>Jan 23 5 task </Text>
</Card>
<Card>
<Text>Jan 24 2 task </Text>
</Card>
</Container>
);
}
const Container = styled.div`
display: flex;
flex-direction: row;
`;
const Card = styled.div`
background-color: lightblue;
height: 100px;
width: 300px;
border-radius: 20px;
margin: 10px;
`;
const Text = styled.text`
font-size: 12px;
padding: 20px;
`;
这是我在 json 中的 dymmydata
{
"data": [
{
"dueDatetime": "2021-01-21T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-03-15T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-01-22T16:30:11.007867Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-01-23T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-01-25T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-04-15T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-04-15T16:30:11.007867Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-04-26T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-01-22T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-05-15T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-05-15T16:30:11.007867Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-05-24T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-02-07T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-01-22T16:30:11.007867Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-06-17T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-01-21T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-07-05T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-07-15T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-07-15T16:30:11.007867Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-07-19T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-08-02T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-08-15T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-01-22T16:30:11.007867Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-08-16T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-08-30T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-09-13T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-09-15T16:30:11.007867Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-09-16T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-01-23T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-01-21T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-10-15T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-10-15T16:30:11.007867Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-10-25T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-11-08T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-01-22T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-11-15T16:30:11.007867Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-11-22T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-12-06T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-12-15T16:30:11.007867Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-12-16T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2019-12-20T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2020-01-03T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2020-01-15T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2020-01-15T16:30:11.007867Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2020-01-17T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2020-01-31T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2020-02-14T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2020-02-15T16:30:11.007867Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2020-02-17T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-01-22T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2020-03-13T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2020-03-14T22:28:14Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2020-03-15T16:30:11.007867Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2020-03-16T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-01-27T13:37:56.587949Z",
"repeatInformation": {
"type": "weeks",
"interval": 2,
"day": null,
"annualStart": null,
"annualEnd": null
}
},
{
"dueDatetime": "2021-01-23T14:30:22.149836Z",
"repeatInformation": {
"type": "months",
"interval": 1,
"day": "any weekday",
"annualStart": null,
"annualEnd": null
}
}
]
}
【问题讨论】:
标签: javascript sorting date