You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/en/functions/time.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,32 +13,32 @@ menu:
13
13
keywords: [dates,time,location]
14
14
signature: ["time INPUT [LOCATION]"]
15
15
workson: []
16
-
hugoversion:
16
+
hugoversion:"v0.77.0"
17
17
relatedfuncs: []
18
18
deprecated: false
19
19
aliases: []
20
20
---
21
21
22
-
`time` converts a timestamp string with an optional timezone into a [`time.Time`](https://godoc.org/time#Time) structure so you can access its fields:
22
+
`time` converts a timestamp string with an optional default location into a [`time.Time`](https://godoc.org/time#Time) structure so you can access its fields:
23
23
24
24
```
25
25
{{ time "2016-05-28" }} → "2016-05-28T00:00:00Z"
26
26
{{ (time "2016-05-28").YearDay }} → 149
27
27
{{ mul 1000 (time "2016-05-28T10:30:00.00+10:00").Unix }} → 1464395400000, or Unix time in milliseconds
28
28
```
29
29
30
-
## Using Timezone
30
+
## Using Locations
31
31
32
-
The optional 2nd parameter [LOCATION] argument is a string that references a timezone that is associated with the specified time value. If the time value has an explicit timezone or offset specified, it will take precedence over an explicit [LOCATION].
32
+
The optional `LOCATION` parameter is a string that sets a default location that is associated with the specified time value. If the time value has an explicit timezone or offset specified, it will take precedence over the `LOCATION` parameter.
33
+
34
+
The list of valid locations may be system dependent, but should include `UTC`, `Local`, or any location in the [IANA Time Zone database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
33
35
34
36
```
35
37
{{ time "2020-10-20" }} → 2020-10-20 00:00:00 +0000 UTC
36
38
{{ time "2020-10-20" "America/Los_Angeles" }} → 2020-10-20 00:00:00 -0700 PDT
37
39
{{ time "2020-01-20" "America/Los_Angeles" }} → 2020-01-20 00:00:00 -0800 PST
38
40
```
39
41
40
-
> **Note**: Timezone support via the [LOCATION] parameter is included with Hugo `0.77`.
41
-
42
42
## Example: Using `time` to get Month Index
43
43
44
44
The following example takes a UNIX timestamp---set as `utimestamp: "1489276800"` in a content's front matter---converts the timestamp (string) to an integer using the [`int` function][int], and then uses [`printf`][] to convert the `Month` property of `time` into an index.
0 commit comments