我如何仅从字符串“ 2022-05-25T15:48:50.000Z”获得日期。使用Moment.js?
我正在使用Moment.JS库,例如,我有代码 -
从“ Mists timeZone”中导入;
const date =“ 2022-05-25t15:48:50.000 z“
我已经尝试使用moment(date).format(“ yyyy-mm-dd”)
,但结果我要获得上一个日期-2022-05-24。
我知道这与UTC有关,并且我的项目在设置了“ MONS.TZ.SETDEFAULT(“ etc/utc””)的行中,从我的理解中可以解决它,但事实并非如此。
我只需要它具有2022-05-25的最终结果,我知道我在这里缺少一些很小的东西。.
我感谢任何帮助!
I am using moment.js library and for the example lets say I have the code -
import moment from "moment-timezone";
const date = "2022-05-25T15:48:50.000Z"
I've tried using moment(date).format("YYYY-MM-DD")
but I am getting the previous date - 2022-05-24 as a result.
I know it has to do with utc, and my project has in it's setting the line 'moment.tz.setDefault("Etc/UTC")` which from my understand is supposed to fix it, but it doesn't.
I only need it to have the final result of 2022-05-25 and I know I am missing something really small here..
I'd appreciate any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下
var newstringdate = yourdate.toisstring()。切片(0,10);
或者
try this
var newStringDate = yourDate.toISOString().slice(0, 10);
or
您的格式为ISO8601格式,您可以从此处检查: https://en.wikipedia.org/wiki/ ISO_8601
您可以尝试将完整格式发送到功能
Your format is ISO8601 format, you could check from here: https://en.wikipedia.org/wiki/ISO_8601
You can try to send the full format to the function