# time.Duration
> 使用给定的时间单位与数值返回 time.Duration 值。
- 官方英文原文：https://gohugo.io/functions/time/duration/
- 本页规范地址：https://hugozh.cn/functions/time/duration/
- 最近更新：2026-10-02
- 最后提交：912b1d3 chore(site): 添加 static/CNAME（hugozh.cn），供 GitHub Pages 等平台绑定自定义域名
- 签名：time.Duration TIME_UNIT NUMBER
- 返回类型：time.Duration
- 站点：Hugo 中文文档（https://hugozh.cn/）· 社区维护的非官方中文翻译，如有出入以官方英文原文为准

---
`time.Duration` 函数返回一个 [`time.Duration`][] 值，可与任意 `Duration` [方法][methods]配合使用。

以下模板：

```go-html-template
{{ $duration := time.Duration "hour" 24 }}
{{ printf "There are %.0f seconds in one day." $duration.Seconds }}
```

渲染为：

```text
There are 86400 seconds in one day.
```

时间单位必须是以下之一：

时长|有效时间单位
:--|:--
hours|`hour`, `h`
minutes|`minute`, `m`
seconds|`second`, `s`
milliseconds|`millisecond`, `ms`
microseconds|`microsecond`, `us`, `µs`
nanoseconds|`nanosecond`, `ns`

[`time.Duration`]: https://pkg.go.dev/time#Duration
[methods]: /methods/duration/

