强制react-datepicker使用UTC
如果选择,则开始时为 null。
当我选择日期 20/04/2022 时,
Datepicker 显示 20/04/2022
Console.log 显示 Wed Apr 20 2022 00:00:00 GMT+0200(中欧夏令时间),
但表单上的有效负载显示 2022-04- 19T22:00:00.000Z
我可以将格式锁定为 UTC 吗?
If selected starts out as null.
When I select a date 20/04/2022
Datepicker shows 20/04/2022
Console.log shows Wed Apr 20 2022 00:00:00 GMT+0200 (Central European Summer Time)
But my payload on the form shows 2022-04-19T22:00:00.000Z
Can I lock the format to UTC?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想完全忽略用户的本地时区,甚至不使用它来显示或发送到 API。为了做到这一点,我使用他们的时区来解析来自我的目标 api 时区 (utc) 的日期。这对我有用:
它在 momentjs b/c 中,我们的代码很旧,可以在较新的库中复制
Playground 版本(链接)
I wanted to just completely disregard the user's local timezone, and not even use it for display or for sending to the API. In order to do that, I used their timezone just to parse dates back and forth from my target api timezone (utc). This is working for me:
it's in momentjs b/c our code is old, can replicate in newer libs
Playground Version (link)
这是 react-datepicker 的已知问题。
您有 2 种可能的解决方案 -
或者
用户的日期选择。
您可以在此处查看第二个解决方案的问题和代码实现和<一个href="https://github.com/Hacker0x01/react-datepicker/issues/1787#issuecomment-770313939" rel="nofollow noreferrer">此处。
This is known issue for react-datepicker.
You have 2 possible solutions -
or
date selection of the user.
You can see the the issue and code implementation of the 2nd solution here and here.