Skip to main content

time.Format

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:

Layout string​

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:

TokenResult
:date_fullFriday, January 27, 2023
:date_longJanuary 27, 2023
:date_mediumJan 27, 2023
:date_short1/27/23
:time_full11:44:58 pm Pacific Standard Time
:time_long11:44:58 pm PST
:time_medium11:44:58 pm
:time_short11:44 pm

Localized to de-DE:

TokenResult
:date_fullFreitag, 27. Januar 2023
:date_long27. Januar 2023
:date_medium27.01.2023
:date_short27.01.23
:time_full23:44:58 Nordamerikanische Westküsten-Normalzeit
:time_long23:44:58 PST
:time_medium23:44:58
:time_short23:44