Skip to main content
Version: Java (Groovy)

parseDuration

parseDuration parses a string argument as a Duration, which is a unit of time in terms of wall clock time (days, hours, minutes, seconds, and nanoseconds).

Duration strings are formatted according to the ISO-8601 duration format as [-]PnDTnHnMn.nS, where the coefficients can be positive or negative. Zero coefficients can be omitted. Optionally, the string can begin with a negative sign.

Throws an exception if the string cannot be parsed.

Syntax

parseDuration(s)

Parameters

ParameterTypeDescription
sstring

The string to be converted.

Time duration strings can be formatted as [-]PT[-]hh:mm:[ss.nnnnnnnnn] or as a duration string formatted as [-]PnDTnHnMn.nS.yyyy-MM-ddThh:mm:ss[.SSSSSSSSS] TZ

Returns

A Duration.

Examples


one_day = parseDuration("P1D")
one_hour = parseDuration("PT1H")
println one_day
println one_hour