【发布时间】:2020-05-21 13:56:25
【问题描述】:
我的本地时区是 IST,我尝试在 Date 对象中定义时区,例如
const usaRegionTime = new Date(inputDate.toString()).toLocaleString(
'en-US',
{
timeZone: 'America/New_York',
}
);
const estDate = new Date(usaRegionTime);
console.log(estDate.getTime());// Uses IST(local time Zone) instead of EST(Specifed time zone)
示例:
我的 IST 时间是晚上 7:15,我使用带有 EST 时区的 Date 对象,我得到正确的 EST 作为上午 9:45,但是当我尝试 est.getTime() 时,UTC 计算为晚上 7:15 而不是 1:下午 45 点。在转换为 UTC(纪元)之前,它以上午 9:45 作为 IST(本地时区)。
问题是它以浏览器本地 timeZone(IST) 而不是 TimeZone(EST) 我作为参数提供给 Date 对象以获取 Epoch 值。有没有办法在获取 Epoch 值的同时用 Specified TimeZone 覆盖 Local time Zone。
【问题讨论】:
标签: javascript angular date timezone