time.Duration
语法
time.Duration TIME_UNIT NUMBER
返回值
time.Duration
别名
duration
time.Duration 函数返回一个 time.Duration 值,您可以将其与任何 Duration 方法一起使用。
此模板
{{ $duration := time.Duration "hour" 24 }}
{{ printf "There are %.0f seconds in one day." $duration.Seconds }}
渲染为
There are 86400 seconds in one day.
时间单位必须是以下之一
| Duration | 有效时间单位 |
|---|---|
| 小时 | hour, h |
| 分钟 | minute, m |
| 秒 | second, s |
| 毫秒 | millisecond, ms |
| 微秒 | microsecond, us, µs |
| 纳秒 | nanosecond, ns |