ISO 8601 Duration with milliseconds?

Werner picture Werner · Nov 21, 2014 · Viewed 7.6k times · Source

How should a duration of 500 milliseconds be expressed using ISO 8601? To me, the documentation is not 100% clear. Is it just "PT0.5S" ?

Answer

Serge Ballesta picture Serge Ballesta · May 28, 2018

Yes.

I could only find an old draft for 8601 but it is explicit on the fractional representation:

5.5 Periods of time

5.5.1 Means of specifying periods of time

A period of time shall be expressed in one of the following ways:

a) As a duration delimited by a specific start and a specific end;

b) As a duration expressed in one or more specific components but not associated with any specific start or end;

c) As a duration associated with a specific start;

d) As a duration associated with a specific end.

5.5.2 Separators and designators

A solidus [/] shall be used to separate the two components in each of 5.5.1 a), c) and d).

For 5.5.1 b), c) and d) the designator [P] shall precede, without spaces, the representation of the duration.

Other designators (and the hyphen when used to indicate omitted components) shall be used as shown in 5.5.4 and 5.5.5 below.

and later

5.5.3.1 Format with time-unit designators

In expressions of period of time or recurring time-interval duration can be represented by a data element of variable length. The number of years shall be followed by the designator [Y], the number of months by [M], the number of weeks by [W], and the number of days by [D]. The part including time components shall be preceded by the designator [T]; the number of hours shall be followed by [H], the number of minutes by [M] and the number of seconds by [S]. In the examples [n] represents one or more digits, constituting a positive integer or zero.

In complete representations the format shall be nYnMnDTnHnMnS or nW.

For reduced precision, decimal or truncated representations of this format of duration the following rules apply:

a) If necessary for a particular application the lowest order components may be omitted to represent duration with reduced precision;

b) If necessary for a particular application the lowest order component may have a decimal fraction. The decimal fraction shall be divided from the integer part by the decimal sign specified in ISO 31-0: i.e. the comma [,] or full stop [.]. Of these, the comma is the preferred sign. If the magnitude of the number is less than unity, the decimal sign shall be preceded by a zero (see ISO 31-0);

c) If the number of years, months, days, hours, minutes or seconds in any of these expressions equals zero, the number and the corresponding designator may be absent; however, at least one number and its designator shall be present. Note that the removal of leading non-zero components is not allowed;

d) The designator T shall be absent if all of the time components are absent.

All this is coherent with the wikipedia article, so the ISO-8601 of a duration of 500 ms should be PT0,5S or PT0.5S