Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-07-26 19:28:57 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-07-27 20:02:48 +0300
commita57dda854b5efd3429af5f0b1564fc9d9d5439b9 (patch)
tree8e01442c7c43cc5bef5c9d5dbfdb3e0132736efe /docs/content/en
parentf9afba933579de07d2d2e36a457895ec5f1b7f01 (diff)
Localize time.Format
Fixes #8797
Diffstat (limited to 'docs/content/en')
-rw-r--r--docs/content/en/functions/dateformat.md44
1 files changed, 34 insertions, 10 deletions
diff --git a/docs/content/en/functions/dateformat.md b/docs/content/en/functions/dateformat.md
index e5fb3608d..d56a91f02 100644
--- a/docs/content/en/functions/dateformat.md
+++ b/docs/content/en/functions/dateformat.md
@@ -1,6 +1,6 @@
---
-title: dateFormat
-description: Converts the textual representation of the `datetime` into the specified format.
+title: time.Format
+description: Converts a date/time to a localized string.
godocref: https://golang.org/pkg/time/
date: 2017-02-01
publishdate: 2017-02-01
@@ -10,23 +10,47 @@ menu:
docs:
parent: "functions"
keywords: [dates,time,strings]
-signature: ["dateFormat LAYOUT INPUT"]
+signature: ["time.Format LAYOUT INPUT"]
workson: []
hugoversion:
relatedfuncs: [Format,now,Unix,time]
deprecated: false
---
-`dateFormat` converts a timestamp string `INPUT` into the format specified by the `LAYOUT` string.
+`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.
+```go-html-template
+{{ time.Format "Monday, Jan 2, 2006" "2015-01-21" }} → "Wednesday, Jan 21, 2015"
```
-{{ dateFormat "Monday, Jan 2, 2006" "2015-01-21" }} → "Wednesday, Jan 21, 2015"
-```
-{{% warning %}}
-As of v0.19 of Hugo, the `dateFormat` function is *not* supported as part of Hugo's [multilingual feature](/content-management/multilingual/).
-{{% /warning %}}
+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:
-See [Go’s Layout String](/functions/format/#gos-layout-string) to learn about how the `LAYOUT` string has to be formatted. There are also some useful examples.
+* [Go’s Layout String](/functions/format/#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](/functions/time/) 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:
+
+```go-html-template
+{{ .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`