如何根据JS中的当前DateTime获取UTC DateTime?

发布于 2025-02-04 20:06:12 字数 443 浏览 4 评论 0原文

我尝试根据用户的当前日期时间获取DateTime。例如,如果我想在UTC中获得当前日期的开始,

const start = new Date()
start.setUTCHours(0,0,0,0)

如果我想在UTC中结束当前日期,

const end = new Date()
end.setUTCHours(23,59,59,999)

但是当我委托时

Sun Jun 05 2022 17:00:00 GMT-0700 (Pacific Daylight Time)

。时间)”? )

那如果我想在5天前获得当前数据呢?该怎么办?就像现在本地日期时间是PST下午2:35一样,我该如何在5天前2:35 PM获得,但在UTC中(应该是7:35 pm,对吗?)谢谢!

I try to get datetime based on user's current datetime. For example, if I want to get the start of the current date in utc,

const start = new Date()
start.setUTCHours(0,0,0,0)

if I want to get the end of the current date in utc,

const end = new Date()
end.setUTCHours(23,59,59,999)

but when I console.log start, it's

Sun Jun 05 2022 17:00:00 GMT-0700 (Pacific Daylight Time)

May I know why there's this "(Pacific Daylight Time)"? )

So what if I want to get 5 days ago of current datetimt? Like if now local datetime is 2:35pm pst, how do I get 5 days ago 2:35 pm but in utc (which should be 7:35pm right?) Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文