mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
e509cac533
cb18a5183Fix broken link07a0198bfConfig: Place Google Analytics tag ID under the services key4bf0c719fFix typo50d8ad1afFix muiltilingual menu definition instructions1a32519a9Fix typos6f34ca8e0Explain usage of front matter to target a template5bd977257Improve goldmark config docs447632938Remove Docker notes from installation instructions84741d173Update reference to hugo.work0338d7c71Fix menu templatef5d2f5ed4Fix typos in content/en/functions/fmta3a40ff99Add return type to functions85ac3e779Remove outdated feature imaged47d889e4Fix signatures7551ba28fDocument safe.JSStr functione77993be0Document keyVals function4dba20db3Update themebabf91544Update echoparam8c8203efaAdjust related functions4cb1b30fcFix exampleba95eca64Improve showcase prose5d3dcf366Add Overmind Studios showcase8d634ac70Change code blocks from indented to fencedcfab978e6Add missing code fences407dd5c47Limit related pages for functions to other functions9fa67d981Fix .Site.LastChange doc393aa16d0netlify: Hugo 0.119.0f864af97adocs: Even more about images.Process9d772d5f0docs: More about images.Processbc655f869docs: Regen docshelper41c3536d1Merge commit '9aec42c5452b3eb224888c50ba1c3f3b68a447e9'918ed53f4Add images.Process filter573645883Add $image.Processa1151b0fdAdd images.Opacity filter git-subtree-dir: docs git-subtree-split:cb18a5183f
2.2 KiB
2.2 KiB
title, description, categories, keywords, menu, function, relatedFunctions, toc
| title | description | categories | keywords | menu | function | relatedFunctions | toc | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| .Format | Returns a formatted time.Time value. |
|
|
|
true |
{{ $t := "2023-01-27T23:44:58-08:00" }}
{{ $t = time.AsTime $t }}
{{ $format := "2 Jan 2006" }}
{{ $t.Format $format }} → 27 Jan 2023
{{% note %}}
To return a formatted and localized time.Time value, use the time.Format function instead.
{{% /note %}}
Use the .Format method with any time.Time value, including the four predefined front matter dates:
{{ $format := "2 Jan 2006" }}
{{ .Date.Format $format }}
{{ .PublishDate.Format $format }}
{{ .ExpiryDate.Format $format }}
{{ .Lastmod.Format $format }}
Layout string
{{% readfile file="/functions/_common/time-layout-string.md" %}}
Examples
Given this front matter:
{{< code-toggle fm=true copy=false >}} title = "About time" date = 2023-01-27T23:44:58-08:00 {{< /code-toggle >}}
The examples below were rendered in the America/Los_Angeles time zone:
| Format string | Result |
|---|---|
Monday, January 2, 2006 |
Friday, January 27, 2023 |
Mon Jan 2 2006 |
Fri Jan 27 2023 |
January 2006 |
January 2023 |
2006-01-02 |
2023-01-27 |
Monday |
Friday |
02 Jan 06 15:04 MST |
27 Jan 23 23:44 PST |
Mon, 02 Jan 2006 15:04:05 MST |
Fri, 27 Jan 2023 23:44:58 PST |
Mon, 02 Jan 2006 15:04:05 -0700 |
Fri, 27 Jan 2023 23:44:58 -0800 |
UTC and local time
Convert and format any time.Time value to either Coordinated Universal Time (UTC) or local time.
{{ $t := "2023-01-27T23:44:58-08:00" }}
{{ $t = time.AsTime $t }}
{{ $format := "2 Jan 2006 3:04:05 PM MST" }}
{{ $t.UTC.Format $format }} → 28 Jan 2023 7:44:58 AM UTC
{{ $t.Local.Format $format }} → 27 Jan 2023 11:44:58 PM PST
Ordinal representation
Use the humanize function to render the day of the month as an ordinal number:
{{ $t := "2023-01-27T23:44:58-08:00" }}
{{ $t = time.AsTime $t }}
{{ humanize $t.Day }} of {{ $t.Format "January 2006" }} → 27th of January 2023