javascript - NodeJS:为什么 new Date().toLocaleString() 忽略系统时区?
问题描述
我的 /etc/timezone 设置为我的本地时区,这是“timedatectl status”的输出:
Local time: Wed 2018-09-26 12:01:32 MDT
Universal time: Wed 2018-09-26 18:01:32 UTC
RTC time: Wed 2018-09-26 18:01:32
Time zone: Etc/UTC (MDT, -0600)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no
“日期”命令打印 Wed Sep 26:12:01:32 MDT 2018。
在 Node 中,“new Date().toLocaleString()”会忽略时区并吐出“2018-09-26 18:01:32”。
有没有办法在 Node 中获取本地时间?到目前为止,我看到的所有答案都声称 Node 无法确定运行它的机器的时区,除非您明确设置“TZ”环境变量,这很荒谬。
解决方案
推荐阅读
- css - 无法更改默认徽标
- javascript - 设置默认回调以响应 setState() 函数
- java - Dvertx.runArgs 无法在 Intellij 中读取为 VM 选项
- openj9 - 我是 OpenJ9 新手,需要在 RCP 应用程序中使用 OpenJ9 分析工具
- dialogflow-es - 谷歌家庭设备用户ID重新生成
- swift - 使用带有旋转精灵的 frame.contains()
- android - Android 应用内结算总是回复错误 3:BILLING_UNAVAILABLE
- wordpress - GTM 和 wordpress
- android - 如果我按下后退按钮,如何保存活动状态?
- android - 把 android:largeHeap="true" 放在不同的设备上会导致不同的行为