ECMAScript 5 Date.parse results for ISO 8601 test cases

天大地大妈咪最大 提交于 2019-11-30 15:44:07

According to the ES5 spec, Date.parse will only work with valid ISO 8601 dates. Anything else is implementation dependent (in practice, IE < 9 doesn't work with standard ISO dates, it requires a '/' seperator). So if you feed it an invalid date (such as 2012-11-31) you can get anythying, from 2012-12-01 to an error.

In your tests:

2012-12-31T23:59:60.000Z

should work, though probably not as you expect. Using 60 for seconds indicates a leap second, it isn't equivalent to 24:00:00, only Safari seems to get that right.

Also:

2012-04-04T24:00:00.000Z

should work, it indicates midnight at the end of 4 April, 2012 so Firefox is in error there.

The formats that ES5 implementations should support are in the spec.

Oh, and you should probably also test omission of the 'T' (since it is optional in certain cases that I think include browsers) and different time zones such as:

2012-04-03 23:50:00+10:00
2012-04-03 23:50:00-04:15
2012-04-03 23:50:00+10
20120403T235000+1000

and so on with YYYYDDD and YYYYWwwD formats, though implementations aren't required to support them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!