[英]Is using timestamp to initialize Date affected by timezone?
My local machine timezone is Asia/China
, UTC+8.我的本地机器时区是
Asia/China
,UTC+8。
new Date(1509692400000).toISOString() // output: 2017-11-03T07:00:00.000Z
When I change the timezone environment variable export TZ=Europe/Amsterdam
, I got the same ISO string of the date.当我更改时区环境变量
export TZ=Europe/Amsterdam
时,我得到了相同的 ISO 日期字符串。
new Date(1509692400000).toISOString() // output: 2017-11-03T07:00:00.000Z
Does this mean using a timestamp to initialize Date
, not affected by timezone?这是否意味着使用时间戳来初始化
Date
,不受时区影响?
So I can use this way to mock the Date when running the unit tests on different remote CI servers with different timezones.因此,在具有不同时区的不同远程 CI 服务器上运行单元测试时,我可以使用这种方式来模拟日期。
As says documentation , toISOString()
method always returns timezone UTC-0.如文档所述,
toISOString()
方法始终返回时区 UTC-0。 In my opinion, if you want to use date in unit tests, shared in unknown-location servers, then setup Date
object as you did and check date using toUTCString()
- docs在我看来,如果你想在单元测试中使用日期,在未知位置的服务器中共享,然后像你一样设置
Date
object 并使用toUTCString()
检查日期 - 文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.