添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
被表白的罐头  ·  diffoscope | x-cmd ...·  5 月前    · 
高大的长颈鹿  ·  系统generate ...·  1 年前    · 
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