Debian Codegraph @

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

raw
1 ---
2 title: time.Duration
3 description: Returns a time.Duration value using the given time unit and number.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [duration]
9 returnType: time.Duration
10 signatures: [time.Duration TIME_UNIT NUMBER]
11 aliases: [/functions/duration]
12 ---
13
14 The `time.Duration` function returns a [`time.Duration`][] value that you can use with any of the `Duration` [methods][].
15
16 This template:
17
18 ```go-html-template
19 {{ $duration := time.Duration "hour" 24 }}
20 {{ printf "There are %.0f seconds in one day." $duration.Seconds }}
21 ```
22
23 Is rendered to:
24
25 ```text
26 There are 86400 seconds in one day.
27 ```
28
29 The time unit must be one of the following:
30
31 Duration|Valid time units
32 :--|:--
33 hours|`hour`, `h`
34 minutes|`minute`, `m`
35 seconds|`second`, `s`
36 milliseconds|`millisecond`, `ms`
37 microseconds|`microsecond`, `us`, `µs`
38 nanoseconds|`nanosecond`, `ns`
39
40 [`time.Duration`]: https://pkg.go.dev/time#Duration
41 [methods]: /methods/duration/