hugo/docs/content/en/functions/time/ParseDuration.md
2023-10-20 09:43:56 +02:00

1 KiB

title description categories keywords menu function relatedFunctions aliases
time.ParseDuration Parses a given duration string into a `time.Duration` structure.
functions
docs
parent
functions
aliases returnType signatures
time.Duration
time.ParseDuration DURATION
time.AsTime
time.Duration
time.Format
time.Now
time.ParseDuration
/functions/time.parseduration

time.ParseDuration parses a duration string into a time.Duration structure so you can access its fields. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as 300ms, -1.5h or 2h45m. Valid time units are ns, us (or µs), ms, s, m, h.

You can perform time operations on the returned time.Duration value:

{{ printf "There are %.0f seconds in one day." (time.ParseDuration "24h").Seconds }}
<!-- Output: There are 86400 seconds in one day. -->