ISO 8601 defines lots of different formats for a date and time, like:
- extended (same used by ECMA):
YYYY-MM-DDTHH:mm:ss.sssZ
- basic (same as above, but without
-
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):
- "incomplete" dates:
- only the year:
YYYY
, or the expanded version with a +
or -
signal before the number
- just year and month:
YYYY-MM
- just month and day:
--MM-DD
- week dates:
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.
- ordinal dates:
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).