time.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.

時間單位必須是以下其中之一:

時間長度 有效時間單位
小時 hour, h
分鐘 minute, m
second, s
毫秒 millisecond, ms
微秒 microsecond, us, µs
奈秒 nanosecond, ns