hugo

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

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

dateformatting.md (2340B)

    1 Go templates [format your dates][time] according to a single reference time:
    2 
    3 ```
    4 Mon Jan 2 15:04:05 MST 2006
    5 ```
    6 
    7 You can think of `MST` as `07`, thus making the reference format string a sequence of numbers. The following is [taken directly from the Go docs][gdex]:
    8 
    9 ```
   10 Jan 2 15:04:05 2006 MST
   11   1 2  3  4  5    6  -7
   12 ```
   13 
   14 ### Hugo Date Templating Reference
   15 
   16 Each of the following examples show the reference formatting string followed by the string Hugo will output in your HTML.
   17 
   18 Note that the examples were rendered and tested in [CST][] and pull from a single example date you might have in your content's front matter:
   19 
   20 ```
   21 date: 2017-03-03T14:15:59-06:00
   22 ```
   23 
   24 `.Date` (i.e. called via [page variable][pagevars])
   25 : **Returns**: `2017-03-03 14:15:59 -0600 CST`
   26 
   27 `"Monday, January 2, 2006"`
   28 : **Returns**: `Friday, March 3, 2017`
   29 
   30 `"Mon Jan 2 2006"`
   31 : **Returns**: `Fri Mar 3 2017`
   32 
   33 `"January 2nd"`
   34 : **Returns**: `March 3rd`
   35 
   36 `"January 2006"`
   37 : **Returns**: `March 2017`
   38 
   39 `"2006-01-02"`
   40 : **Returns**: `2017-03-03`
   41 
   42 `"Monday"`
   43 : **Returns**: `Friday`
   44 
   45 `"02 Jan 06 15:04 MST"` (RFC822)
   46 : **Returns**: `03 Mar 17 14:15 CST`
   47 
   48 `"02 Jan 06 15:04 -0700"` (RFC822Z)
   49 : **Returns**: `03 Mar 17 14:15 -0600`
   50 
   51 `"Mon, 02 Jan 2006 15:04:05 MST"` (RFC1123)
   52 : **Returns**: `Fri, 03 Mar 2017 14:15:59 CST`
   53 
   54 `"Mon, 02 Jan 2006 15:04:05 -0700"` (RFC339)
   55 : **Returns**: `Fri, 03 Mar 2017 14:15:59 -0600`
   56 
   57 ### Cardinal Numbers and Ordinal Abbreviations
   58 
   59 Spelled-out cardinal numbers (e.g. "one", "two", and "three") and ordinal abbreviations (e.g. "1st", "2nd", and "3rd") are not currently supported.
   60 
   61 To continue with the example above:
   62 
   63 ```
   64 {{.Date.Format "Jan 2nd 2006"}}
   65 ```
   66 
   67 Hugo assumes you want to append `nd` as a string to the day of the month and outputs the following:
   68 
   69 ```
   70 Mar 3nd 2017
   71 ```
   72 
   73 ### Use `.Local` and `.UTC`
   74 
   75 In conjunction with the [`dateFormat` function][dateFormat], you can also convert your dates to `UTC` or to local timezones:
   76 
   77 `{{ dateFormat "02 Jan 06 15:04 MST" .Date.UTC }}`
   78 : **Returns**: `03 Mar 17 20:15 UTC`
   79 
   80 `{{ dateFormat "02 Jan 06 15:04 MST" .Date.Local }}`
   81 : **Returns**: `03 Mar 17 14:15 CST`
   82 
   83 [CST]: https://en.wikipedia.org/wiki/Central_Time_Zone
   84 [dateFormat]: /functions/dateformat/
   85 [gdex]: https://golang.org/pkg/time/#example_Time_Format
   86 [pagevars]: /variables/page/
   87 [time]: https://golang.org/pkg/time/