blob: 60e45a91c149a695765a2f60aacc39b2db3a3ab8 (
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
---
title: time.Now
description: Returns the current local time.
categories: []
keywords: []
action:
aliases: [now]
related:
- functions/time/AsTime
- functions/time/Duration
- functions/time/Format
- functions/time/ParseDuration
returnType: time.Time
signatures: [time.Now]
aliases: [/functions/now]
---
For example, when building a site on October 15, 2023 in the America/Los_Angeles time zone:
```go-html-template
{{ time.Now }}
```
This produces a `time.Time` value, with a string representation such as:
```text
2023-10-15 12:59:28.337140706 -0700 PDT m=+0.041752605
```
To format and [localize] the value, pass it through the [`time.Format`] function:
```go-html-template
{{ time.Now | time.Format "Jan 2006" }} → Oct 2023
```
The `time.Now` function returns a `time.Time` value, so you can chain any of the [time methods] to the resulting value. For example:
```go-html-template
{{ time.Now.Year }} → 2023 (int)
{{ time.Now.Weekday.String }} → Sunday
{{ time.Now.Month.String }} → October
{{ time.Now.Unix }} → 1697400955 (int64)
```
[`time.Format`]: /functions/time/format
[localize]: /getting-started/glossary/#localization
[time methods]: /methods/time/
|