gpt4 book ai didi

javascript - 创建 javascript Date() 对象到 America/New_York 时区

转载 作者:行者123 更新时间:2023-12-03 02:19:32 24 4
gpt4 key购买 nike

代码:

console.log(start)

读取,2018 年 3 月 1 日星期四 00:00:00 GMT+0530(印度标准时间)

我想要一个新对象 start_NY ,它将读取 Thu Mar 01 2018 00:00:00 w.r.t. America/New_York 时区。类似于 2018 年 3 月 1 日星期四 00:00:00 GMT-0500

我使用了一个脚本:

start_ny = new Date('Thu Mar 01 2018 00:00:00 GMT-0500');

但是上面写着,Thu Mar 01 2018 10:30:00 GMT+0530(印度标准时间),这实际上是将日期转换为印度标准时间,而不是给我一个时间纽约时区。

格式应与现有格式相同。我怎样才能做到这一点?

最佳答案

尝试使用以下代码和 MDN资源

new Date().toLocaleString('en-US', { timeZone: 'America/New_York' })

// Date Format

new Date().toDateString('en-US', { timeZone: 'America/New_York' });

关于javascript - 创建 javascript Date() 对象到 America/New_York 时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49221517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com