hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

dateformat.md (1788B)

    1 ---
    2 title: time.Format
    3 description: Converts a date/time to a localized string.
    4 date: 2017-02-01
    5 publishdate: 2017-02-01
    6 lastmod: 2017-02-01
    7 categories: [functions]
    8 menu:
    9   docs:
   10     parent: "functions"
   11 keywords: [dates,time,strings]
   12 signature: ["time.Format LAYOUT INPUT"]
   13 workson: []
   14 hugoversion:
   15 relatedfuncs: [Format,now,Unix,time]
   16 deprecated: false
   17 ---
   18 
   19 `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.
   20 
   21 ```go-html-template
   22 {{ time.Format "Monday, Jan 2, 2006" "2015-01-21" }} → "Wednesday, Jan 21, 2015"
   23 ```
   24 
   25 Note that since Hugo 0.87.0, `time.Format` will return a localized string for the current language. {{< new-in "0.87.0" >}}
   26 
   27 The `LAYOUT` string can be either:
   28 
   29 * [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.
   30 * A custom Hugo layout identifier (see full list below)
   31 
   32 See the [`time` function](/functions/time/) to convert a timestamp string to a Go `time.Time` type value.
   33 
   34 
   35 ## Date/time formatting layouts
   36 
   37 {{< new-in "0.87.0" >}}
   38 
   39 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 identifiers that will output localized dates or times:
   40 
   41 ```go-html-template
   42 {{ .Date | time.Format ":date_long" }}
   43 ```
   44 
   45 The full list of custom layouts with examples for English:
   46 
   47 * `:date_full` => `Wednesday, June 6, 2018`
   48 * `:date_long` => `June 6, 2018`
   49 * `:date_medium` => `Jun 6, 2018`
   50 * `:date_short` => `6/6/18`
   51 
   52 * `:time_full` => `2:09:37 am UTC`
   53 * `:time_long` => `2:09:37 am UTC`
   54 * `:time_medium` => `2:09:37 am`
   55 * `:time_short` => `2:09 am`