time.Duration
Returns a time.Duration value using the given time unit and number.
- Syntax
- time.Duration TIME_UNIT NUMBER
- Returns
- time.Duration
- Alias
- duration
Usage
The time.Duration function returns a time.Duration value using the given time unit and number. Use any of the Duration methods with the returned value.
Arguments
TIME_UNIT- (
string) The unit of time, one ofhour,minute,second,millisecond,microsecond, ornanosecond. You can also use the abbreviationsh,m,s,ms,us, andns, orµsfor microseconds. NUMBER- (
int) The number of time units. If you pass a floating-point number, the function discards the fractional part.
Examples
{{ time.Duration "hour" 24 }} → 24h0m0s
{{ time.Duration "ms" 1500 }} → 1.5sCalling a method on the returned value:
{{ (time.Duration "hour" 24).Seconds }} → 86400Last updated:
November 8, 2026
:
content: Remove categories from front matter (1cc1dd83a)
Improve this page