hugo/content/en/functions/dateformat.md
Bjørn Erik Pedersen bd77f6e1c9 Squashed 'docs/' changes from 60a58d123..327003421
327003421 Update index.md
cafdccc13 Hugo 0.86.1
467a89a02 Merge branch 'v0861'
a22c37bc9 Merge branch 'release-0.86.1'
276da91a8 releaser: Add release notes to /docs for release of 0.86.1
198cdf8f0 tpl/lang: Add new localized versions of lang.FormatNumber etc.
93f986ecc Add timezone support for front matter dates without one
b30b876bb Localize time.Format
950fdab90 Fix AddDate documentation
78d7b52b6 Document config.cascade
fd1e1e4b7 Fix grammar and spelling (#1497)
05bf3aa32 Fix grammar / typos in news
32060a3b4 One more try
f6e24ddfa PNG to JPG for the rel notes image
9ec5bdfad Update index.md
5f5d7f69d Release Hugo 0.86.0
2dd60bb71 releaser: Add release notes to /docs for release of 0.86.0
6445fb36c Merge commit '53a352795a69a9d4a373f50ec62138595948c6ea'
cb57ca73a Simplify "active menu" logic for section menus

git-subtree-dir: docs
git-subtree-split: 327003421d8c07f9764aaaf644626805287fd30c
2021-08-03 11:51:36 +02:00

1.8 KiB
Raw Blame History

title description godocref date publishdate lastmod categories menu keywords signature workson hugoversion relatedfuncs deprecated
time.Format Converts a date/time to a localized string. https://golang.org/pkg/time/ 2017-02-01 2017-02-01 2017-02-01
functions
docs
parent
functions
dates
time
strings
time.Format LAYOUT INPUT
Format
now
Unix
time
false

time.Format (alias dateFormat) converts either a time.Time object (e.g. .Date) or a timestamp string INPUT into the format specified by the LAYOUT string.

{{ time.Format "Monday, Jan 2, 2006" "2015-01-21" }} → "Wednesday, Jan 21, 2015"

Note that since Hugo 0.87.0, time.Format will return a localized string for the currrent language. {{< new-in "0.87.0" >}}

The LAYOUT string can be either:

  • Gos Layout String to learn about how the LAYOUT string has to be formatted. There are also some useful examples.
  • A custom Hugo layout identifier (see full list below)

See the time function to convert a timestamp string to a Go time.Time type value.

Date/time formatting layouts

{{< new-in "0.87.0" >}}

Go's date layout strings can be hard to reason about, especially with multiple languages. Since Hugo 0.87.0 you can alternatively use some predefined layout idenfifiers that will output localized dates or times:

{{ .Date | time.Format ":date_long" }}

The full list of custom layouts with examples for English:

  • :date_full => Wednesday, June 6, 2018

  • :date_long => June 6, 2018

  • :date_medium => Jun 6, 2018

  • :date_short => 6/6/18

  • :time_full => 2:09:37 am UTC

  • :time_long => 2:09:37 am UTC

  • :time_medium => 2:09:37 am

  • :time_short => 2:09 am