parseDurationNanosQuiet
parseDurationNanosQuiet
converts a string representing a period or Duration to nanoseconds. Time duration strings can be formatted as [-]PT[-]hh:mm:[ss.nnnnnnnnn]
or as a duration string formatted as [-]PnDTnHnMn.nS
.
"Quiet" methods return null
instead of throwing an exception when encountering a string that cannot be parsed.
Syntax
parseDurationNanosQuiet(s)
Parameters
Parameter | Type | Description |
---|---|---|
s | string | The string to be converted. Time duration strings can be formatted as |
Returns
Nanoseconds representation of the time string, or null
if invalid input is given.
Examples
one_day_nanos = parseDurationNanosQuiet("P1D")
one_hour_nanos = parseDurationNanosQuiet("PT1H")
println one_day_nanos
println one_hour_nanos
- Log