blob: e3abc7c1521de833c798311b582a95b213ae1383 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
---
title: time.ParseDuration
description: Parses a given duration string into a `time.Duration` structure.
categories: [functions]
keywords: []
menu:
docs:
parent: functions
function:
aliases: []
returnType: time.Duration
signatures: [time.ParseDuration DURATION]
relatedFunctions:
- time.AsTime
- time.Duration
- time.Format
- time.Now
- time.ParseDuration
aliases: [/functions/time.parseduration]
---
`time.ParseDuration` parses a duration string into a [`time.Duration`](https://pkg.go.dev/time#Duration) structure so you can access its fields.
A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as `300ms`, `-1.5h` or `2h45m`. Valid time units are `ns`, `us` (or `µs`), `ms`, `s`, `m`, `h`.
You can perform [time operations](https://pkg.go.dev/time#Duration) on the returned `time.Duration` value:
```go-html-template
{{ printf "There are %.0f seconds in one day." (time.ParseDuration "24h").Seconds }}
<!-- Output: There are 86400 seconds in one day. -->
```
|