javascript - Firefox 浏览器上带有时区错误的 JavaScript 日期对象
问题描述
我需要使用时区 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
需要建议来解决它。
解决方案
始终尝试使用 UTC 日期,这意味着将 Dates 存储和执行计算为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"
推荐阅读
- r - R:将数据框拆分为列并重新组合为行
- python - 在chrome无头模式下使用python selenium定位部分链接文本
- ios - SQFlite 无法在 iOS 14.3 上插入数据库
- arrays - 为什么 for 循环用最新的字符串填充整个数组?
- node.js - 如何使用 pkg 中的 figlet 模块编译 Node.js?
- azure-web-app-service - 基于spring boot问题从github repo加载的azure web app
- python - 随机 nr gen python(标题无法持续工作)
- django - Django 表单 - 允许用户为其他用户创建组
- python - __init__() 接受 2 个位置参数,但给出了 3 个尝试使用 presence_of_element_located() 等待元素
- node.js - 当进程消耗大量内存时,NodeJs 会变慢