dateFormat
Use the
time.Format
function with
time.Time
values:
{{ $t := time.AsTime "2023-02-27T23:44:58-08:00" }}
{{ time.Format "2 Jan 2006" $t }} → 27 Feb 2023
Or use
time.Format
with a
parsable
string representation of a date/time value:
{{ $t := "27 Feb 2023" }}
{{ time.Format "January 2, 2006" $t }} → February 27, 2023
Examples of parsable string representations:
The last four examples are not fully qualified. Without a time zone offset, the time zone is set to Etc/UTC (Coordinated Universal Time).
Layout string
Format a
time.Time
value based on
Go’s reference time
:
Mon Jan 2 15:04:05 MST 2006
Create a layout string using these components:
Description
Valid components
{{ $t := "2023-01-27T23:44:58-08:00" }}
{{ $t = time.AsTime $t }}
{{ $t = $t.Format "Jan 02, 2006 3:04 PM Z07:00" }}
{{ $t }} → Jan 27, 2023 11:44 PM -08:00
Strings such as
PST
and
CET
are not time zones. They are time zone
abbreviations
.
Strings such as
-07:00
and
+01:00
are not time zones. They are time zone
offsets
.
A time zone is a geographic area with the same local time. For example, the time zone abbreviated by
PST
and
PDT
(depending on Daylight Savings Time) is
America/Los_Angeles
.
Localization
Use the
time.Format
function to localize
time.Time
values for the current language and region.
Use the layout string as described above, or one of the tokens below. For example:
{{ .Date | time.Format ":date_medium" }} → Jan 27, 2023
Localized to en-US:
Token
Result
Last updated: December 4, 2023:
Squashed 'docs/' changes from 4d936aee6..4dd2d6415 (35dec7c96)
Improve this page