gpt4 book ai didi

javascript - Date.prototype.toISOString() 未返回正确的结果

转载 作者:行者123 更新时间:2023-11-28 18:32:55 29 4
gpt4 key购买 nike

来自此函数的描述 https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString

The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 characters long: YYYY-MM-DDTHH:mm:ss.sssZ. The timezone is always zero UTC offset, as denoted by the suffix "Z".

它应该始终返回 24 个字符长。检查以下示例:

var d = new Date('08AUG20144');
d.toISOString();

返回 +020144-08-08T04:00:00.000Z,长度为 27 个字符。有什么理由吗?

最佳答案

ECMAScript 规范 says about Extended Years :

ECMAScript requires the ability to specify 6 digit years (extended years); approximately 285,426 years, either forward or backward, from 01 January, 1970 UTC. To represent years before 0 or after 9999, ISO 8601 permits the expansion of the year representation, but only by prior agreement between the sender and the receiver. In the simplified ECMAScript format such an expanded year representation shall have 2 extra year digits and is always prefixed with a + or – sign. The year 0 is considered positive and hence prefixed with a + sign.

I've adapted the MDN docs .

关于javascript - Date.prototype.toISOString() 未返回正确的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37643176/

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