What is simplified in ECMAScript 5 date format compared to ISO 8601
ECMAScript defines a string interchange format for date-times based upon a simplification of the ISO 8601 Extended Format. The format is as follows: YYYY-MM-DDTHH:mm:ss.sssZ
— https://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15
So what exactly is the difference between the two formats? What do I have to be careful about? I noticed that ISO 8601 states that the T
can be substituted by a space. What else is "simplified"?
To be very specific: This question is about the standard. Browser behavior is interesting, but not the main focus of this question.
ISO 8601 defines lots of different formats for a date and time, like:
YYYY-MM-DDTHH:mm:ss.sssZ
-
and :
separators): YYYYMMDDTHHmmss.sssZ
And also the variations: just the date, just the time and with or without offset. If a date uses one of the above (basic or extended), the time must use the same.
And it also allows another formats for the date (not used by ECMA):
YYYY
, or the expanded version with a +
or -
signal before the number YYYY-MM
--MM-DD
YYYY-Www
or YYYY-Www-D
. Www
is the week number (an uppercase W
followed by 2 digits), but YYYY
in this case is the ISO week-numbering year - quoting wikipedia: The ISO week-numbering year starts at the first day (Monday) of week 01 and ends at the Sunday before the new ISO year (hence without overlap or gap). It consists of 52 or 53 full weeks. The first ISO week of a year may have up to three days that are actually in the Gregorian calendar year that is ending; if three, they are Friday, Saturday, and Sunday. Similarly, the last ISO week of a year may have up to three days that are actually in the Gregorian calendar year that is starting; if three, they are Monday, Tuesday and Wednesday. The Thursday of each ISO week is always in the Gregorian calendar year denoted by the ISO week-numbering year.
YYYY-DDD
( year and day of the year ). Example:
2017-02-01
is the same as 2017-032
( February 1st is the 32th day of the year ). The week and ordinal formats above can also be used with a time.
Example: 2017-02-01T10:00
and 2017-032T10:00
are both valid (and equivalent).
ECMA simplifies it by allowing only YYYY-MM-DDTHH:mm:ss.sssZ
. It also allows extended years (with 6 digits and a signal), but keeping the same format for the other fields.
ISO 8601 also defines another concepts (Durations and Time Intervals). Although they're both related to dates and times, they're not the same thing: a duration is an "amount of time" (like "2 days, 4 hours and 5 minutes") and an interval is the "intervening time between two time points" (with start and end dates).
ISO 8601 is a standard for a whole range of time and date formats, including:
The ECMA-262 specification (20.3.1.16 in the 2017 version) only implements the date and time.
链接地址: http://www.djcxy.com/p/35116.html