hugo/docs/content/en/functions/time/ParseDuration.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1 KiB

title description categories keywords action aliases
time.ParseDuration Returns a time.Duration value by parsing the given duration string.
aliases related returnType signatures
functions/time/AsTime
functions/time/Duration
functions/time/Format
functions/time/Now
time.Duration
time.ParseDuration DURATION
/functions/time.parseduration

The time.ParseDuration function returns a time.Duration value that you can use with any of the Duration methods.

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.

This template:

{{ $duration := time.ParseDuration "24h" }}
{{ printf "There are %.0f seconds in one day." $duration.Seconds }}

Is rendered to:

There are 86400 seconds in one day.