解析日期没有时间在React JS中?
谁能帮助我使用React日历日期?我正在显示一个我使用的搜索过滤器:
为此,我正在使用React usestate:
const [selectedDate, setSelectedDate] = useState<Date | null >();
<Input label="selected on" type="date" value={startDate} />
现在,选择后,它作为UTC的时间按时间如下:
http://localhost:10000/candidates/projects?page_number=1&page_size=20&selected__date__option=2022-05-25T00:00:00.000Z
我只想从此日期日期,为此我使用以下代码:
const convert = (str: Date): Date => {
const date = new Date(str),
mnth = ("0" + (date.getMonth() + 1)).slice(-2),
day = ("0" + date.getDate()).slice(-2);
return new Date([date.getFullYear(), mnth, day].join("-"));
};
但是返回类型是String
,Usestate寻找date
类型。 那么,谁能指出我在这里缺少什么?
我想要类型的2022-05-26
date
Can anyone help me with react calendar dates? I am showing a search filter where I am using :
for this I am using react useState :
const [selectedDate, setSelectedDate] = useState<Date | null >();
<Input label="selected on" type="date" value={startDate} />
Now, after selection, it is coming as UTC date with time as follows:
http://localhost:10000/candidates/projects?page_number=1&page_size=20&selected__date__option=2022-05-25T00:00:00.000Z
I want only date from this and for that I am using following code:
const convert = (str: Date): Date => {
const date = new Date(str),
mnth = ("0" + (date.getMonth() + 1)).slice(-2),
day = ("0" + date.getDate()).slice(-2);
return new Date([date.getFullYear(), mnth, day].join("-"));
};
but the return type is string
and useState looks for Date
type.
So, can anyone point what I am missing here?
I want selected__date__option=2022-05-26 of type Date
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用此操作
查看MDN上的此文档=&gt;
You can use this action
Check out this documentation on MDN as well => MDN Link