Debian Codegraph @

docs/content/en/functions/time/ParseDuration.md

raw
1 ---
2 title: time.ParseDuration
3 description: Returns a time.Duration value by parsing the given duration string.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: []
9 returnType: time.Duration
10 signatures: [time.ParseDuration DURATION]
11 aliases: [/functions/time.parseduration]
12 ---
13
14 The `time.ParseDuration` function returns a [`time.Duration`][] value that you can use with any of the `Duration` [methods][].
15
16 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`.
17
18 This template:
19
20 ```go-html-template
21 {{ $duration := time.ParseDuration "24h" }}
22 {{ printf "There are %.0f seconds in one day." $duration.Seconds }}
23 ```
24
25 Is rendered to:
26
27 ```text
28 There are 86400 seconds in one day.
29 ```
30
31 [`time.Duration`]: https://pkg.go.dev/time#Duration
32 [methods]: /methods/duration/