javascript - Javascript UTC 时区在 Firefox 中不起作用
问题描述
下面的代码不适用于 Firefox,与 Chrome 完美兼容。有人可以帮我找到替代解决方案吗?
const tempDate = getStartDate['startDate']; // Returns: 2020-08-13 12:52:38
new Date(`${tempDate} UTC`);
Expected Output: Thu Aug 13 2020 08:52:38 GMT-0400 (Eastern Daylight Time)
解决方案
您正在尝试执行以下操作:
new Date('2020-08-13 12:52:38 UTC')
相反,您应该这样做:
new Date('2020-08-13T12:52:38Z')
见https://www.ecma-international.org/ecma-262/11.0/index.html#sec-date-time-string-format
推荐阅读
- ios - 开机时在后台打开iOS应用
- angular - MatToolTip 位置未定义或无效
- python - Python 3.5.1:无法使用 pip 安装 gitpython 包
- node.js - zeromq安装python节点和电子
- javascript - React-native 如何使用 x 和 y 值将视图固定在某个位置
- python - 有没有办法在 Anaconda/Spyder 中更改配置文件的目录?
- android - 从android中的其他活动选定列表项中获取和存储数据在回收站视图中
- apache-spark - 将我的分析项目从 log4j 1.x 迁移到 log4j 2.x 并观察到第三方依赖项为 log4j 1.x
- python - 使用 python 和 Counters 计算一个单词在文本中出现的次数
- python - 在维护索引信息的同时迭代过滤的 Numpy 数组