Firefox 浏览器上存在时区错误的 JavaScript 日期对象

问题描述 投票:0回答:2

我需要使用时区 CST/CDT 创建 javascript 对象,下面的代码行在 chrome 中工作正常,但在 firefox 上不行

new Date("2020-06-06 05:37:34.0" + ' CST/CDT');

镀铬结果:

Sat Jun 06 2020 15:37:34 GMT+0500 (Pakistan Standard Time)

火狐结果:

Invalid Date

需要建议来修复它。

javascript google-chrome date firefox
2个回答
1
投票

始终尝试使用 UTC 日期,这意味着将日期存储为 UTC 并执行计算。

如果您想创建特定于时区的 Date 对象,请执行以下操作,我已经展示了如何将其转换回 UTC/本地时区:

const date = new Date('2010-05-11T10:11:00-0500');//CDT time
console.log(date.toString()); //date as per the current timezone of the machine this code is executed => "Tue May 11 2010 20:41:00 GMT+0530 (India Standard Time)"
console.log(date.toISOString());//converts the Date as UTC based ISO date string => "2010-05-11T15:11:00.000Z"

0
投票

rootka)-[

eth0:flags-4163mtu 1500

如果配置

inet 121168.29.232 网络掩码 255.255.255.0 广播 192.168.29。

255

inet6 2405:201:5509:3c19:b177:865a:5857:22eb prefixlen 64 范围 ID 0x0

inet6 fe80::e646:b177:a18c:f723 prefixlen 64scopeid 0x20

以太 08:00:27:cb:7e:f5 txqueuelen 1000(以太网)

RX 数据包 5303 字节 2806474 (2.6 MiB)

RX 错误丢失 0 超出帧 TX 数据包 3812 字节 563996 (550.7 KiB)

发送错误丢弃超出运营商 0 冲突 0

lo:标志=73mtu 65536

inet 127.0.0.1 网络掩码 255.0.0.0

© www.soinside.com 2019 - 2024. All rights reserved.