ISO 8601

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

External

Internal

Overview

ISO 8601 is a standard aimed at providing unambiguous date and time-related data representation. The standard applies to representations of dates in the Gregorian calendar, of times based on 24-hour timekeeping system (00-24), with an optional UTC offset.

Dates and times are arranged so the largest temporal term is placed to the left, and each successively smaller term is placed to the right of the previous term. The following units are represented: year, month (or week), day, hour, minute, second and fraction of a second. The representation is written as a combination of digits and special characters ("-", ".", "T", "W" and "Z"). Full words such as "January" or "Thursday" are not allowed in ISO 8601 interchange representations. Each date and time has a fixed number of digits, with a leading zero padding.

There are two format: 1. Basic format, with a minimal number of separators. The basic format should be avoided in plain text. 2. Extended format with separators added to enhance human readability.

Separators:

  • "-" (hyphen) is used to separate date values (year, moth, week and day).
  • ":" (colon) is used to separate time values (hours, minutes and seconds).

Values may be dropped from any of the date and time representations, but only in the order from the least to the most significant. "2018-11" is a valid ISO 8601 date.

If necessary for a particular application, the standard supports the addition of a decimal fraction to the smallest time value in the representation.

Combined Date and Time Representation

<date>T<time>

where date representation and time representation are described below.

Date Representation

Year Representation

Years are represented as minimum as four-digit representation:

YYYY
±YYYY

Calendar Date Representation

YYYY-MM-DD (extended format) or YYYYMMDD (basic format)

YYYY-MM (but not YYYYMM) (extended format)

YYYYMM is disallowed to avoid confusion with YYMMDD, which is still often used.

--MM-DD (extended format) or --MMDD (basic format)

MM indicates a two-digit moth of the year, from 01 to 12.

DD indicates a two-digit day of the month, from 01 to 31.

Week Date Representation

YYYY-Www (extended format) or YYYYWww (basic format)

YYYY-Www-D (extended format) or YYYYWwwD (basic format)

Ordinal Dates

YYYY-DDD (extended format) or YYYYDDD (basic format)

Time Representation

hh:mm:ss.sss (extended format) or hhmmss.sss (basic format)

hh:mm:ss (extended format) or hhmmss (basic format)

hh:mm (extended format) or hhmm (basic format)

hh

"hh" refers to zero left-padded hour between 00 and 24. 24 is used to denote midnight and the end of a calendar day. "mm" refers to zero left-padded minute between 00 and 59. "ss" refers to zero left-padded second between 00 and 60, where 60 is only used to denote an added leap second. Seconds, or minutes and seconds can be omitted from the basic and extended form for brevity (but decreased accuracy).

Midnight may be referred to as "00:00" or "24:00". The notation "00:00" is used at the beginning of a calendar day and is the more frequently used. The end of a day is represented as "24:00".

Time Unit Fraction

Decimal fractions may be added to any of the three time elements. However, a fraction may only be added to the lowest order time element in the representation. TODO, more here.

Time Zone Designators

Time zones are represented in ISO 8601 as:

  1. local time with the location unspecified.
  2. UTC.
  3. an offset from UTC.

Local Time

If no UTC relation information is present within the time representation, the time is assumed to be in local time. While it may be safe to assume local time when communicating in the same time zone, it is ambiguous when used in communicating across different time zones. Even within a single geographic time zone, some local times will be ambiguous if the region observes daylight saving time. It is usually preferable to indicate a time zone (zone designator) using the standard's notation.

UTC

A time is indicated as being in UTC by adding a "Z" directly after the time representation. Z is the zone designator for the zero UTC offset. "09:30:01 UTC" is represented as "09:30:01Z" or "093001Z". Z is sometimes referred to as "Zulu time".

<time>Z

Offset from UTC

Time offset from UTC is appended to the time representation in the form of ±[hh]:[mm], ±[hh][mm] or ±[hh]. If the time being described is one hour ahead of UTC, such as the time in Berlin during the winter, the zone designator would be +01:00 or simply +01. The offset from UTC changes with daylight saving time, e.g. a time offset in Chicago, which is in the North American Central Time Zone, would be "−06:00" for the winter (Central Standard Time) and "−05:00" for the summer. To represent time behind UTC, the offset is negative and a hyphen–minus or a minus sign character should be used. If the interchange character set is limited and does not have a minus sign character, then the hyphen–minus should be used. ASCII does not have a minus sign, so its hyphen–minus character (code is 45 decimal or 2D hexadecimal) would be used.

<time>±hh:mm
<time>±hhmm
<time>±hh

To calculate UTC time one has to subtract the offset from the local time, e.g. for "15:00−03:30" do 15:00 − (−03:30) to get 18:30 UTC.

An offset of zero, in addition to having the special representation "Z", can also be stated numerically as "+00:00", "+0000", or "+00". However, it is not permitted to state it numerically with a negative sign, as "−00:00", "−0000", or "−00".

ISO 8601 Time Zone Designators and Java

Java SimpleDateFomat represents ISO 8601 time zone as "X". More:

Java DateFormat Time Zone Offset

Obtaining Date and Time in ISO 8601 with gdate

gdate and ISO 8601 Format

Durations

TODO https://en.wikipedia.org/wiki/ISO_8601#Durations

Time Intervals

TODO https://en.wikipedia.org/wiki/ISO_8601#Time_intervals

Java SimpleDateFormat

Java SimpleDateFormat ISO 8601 Format