【问题标题】:Create javascript Date() object to Amrica/New_York timezone为 America/New_York 时区创建 javascript Date() 对象
【发布时间】:2018-03-11 15:13:41
【问题描述】:

代码:

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 时区。类似于 Thu Mar 01 2018 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 (India Standard Time),这实际上是将日期转换为印度标准时间,而不是给我一个从纽约时区。

格式应与现有格式相同。我该怎么做?

【问题讨论】:

标签: javascript date


【解决方案1】:

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

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

// Date Format

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-04-29
  • 2012-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-28
  • 1970-01-01
相关资源
最近更新 更多