ISO 8601 Duration with milliseconds?

10,536

Solution 1

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

Solution 2

Is it just "PT0.5S" ?

Yes, it is a correct representation.

Test using Java-8 standard library

java.time.Duration is modelled on ISO-8601 standards and was introduced as part of JSR-310 implementation.

Demo:

import java.time.Duration;

public class Main {
    public static void main(String[] args) {
        System.out.println(Duration.ofMillis(500));
    }
}

Output:

PT0.5S

Learn about the modern date-time API from Trail: Date Time.

Share:
10,536
Werner
Author by

Werner

Updated on June 05, 2022

Comments

  • Werner
    Werner almost 2 years

    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" ?

  • linusthe3rd
    linusthe3rd over 8 years
    This answer is not sufficient because ISO 8601 DOES include information about declaring durations of time as noted here: en.wikipedia.org/wiki/ISO_8601#Durations
  • Pablo Pazos
    Pablo Pazos over 2 years
    Though ISO8601 allows fractions in the lowest order component, Java only allows fractions in seconds.