gpt4 book ai didi

JavaScript 日期构造函数和 UTC

转载 作者:行者123 更新时间:2023-12-02 15:43:49 25 4
gpt4 key购买 nike

如果我使用new Date('2015-01-01'),这会给我一个相当于2015-01-01T00:00:00Z的时间点>?

最佳答案

来自documentation :

constructors: ... dateString String value representing a date. The string should be in a format recognized by the Date.parse() method (IETF-compliant RFC 2822 timestamps and also a version of ISO8601).

来自documentation on Date.parse() :

If a time zone is not specified and the string is in an ISO format recognized by ES5, UTC is assumed

但是,依赖此行为可能存在风险,因为来自同一文档:

note that ECMAScript ed 6 draft specifies that date time strings without a time zone are to be treated as local, not UTC

关于JavaScript 日期构造函数和 UTC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32377640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com