parseOrNull

Common
JVM
JS
Native
1.5
fun parseOrNull(value: String): Duration?
(source)

Parses a string that represents a duration and returns the parsed Duration value, or null if the string doesn't represent a duration in any of the supported formats.

The following formats are accepted:

  • ISO-8601 Duration format, e.g. P1DT2H3M4.058S, see toIsoString and parseIsoString.
  • The format of string returned by the default Duration.toString and toString in a specific unit, e.g. 10s, 1h 30m or -(1h 30m).