Skip to content

Instantly share code, notes, and snippets.

@budparr
Last active February 16, 2017 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save budparr/07d31f10270d964805ce32c3c282a663 to your computer and use it in GitHub Desktop.
Save budparr/07d31f10270d964805ce32c3c282a663 to your computer and use it in GitHub Desktop.
{{ dateFormat .Site.Params.DateForm (default .Date (.PublishDate)) }}
<!-- Above is the optimized version of below, thanks to https://discuss.gohugo.io/t/how-to-use-the-publishdate-if-both-publishdate-and-date-are-set-in-frontmatter/5142/3?u=kaushalmodi -->
{{/* with .PublishDate */}}
{{/* if eq ($.PublishDate.Format "2006-01-02") "0001-01-01" */}}
<!-- Print the Date instead of PublishDate if PublishDate is defined but at its initial value of Jan 1, 0001 -->
{{/* $.Date.Format $.Site.Params.DateForm */}}
{{/* else */}}
{{/* $.PublishDate.Format $.Site.Params.DateForm */}}
{{/* end */}}
{{/* end */}}
The layout string used by the Parse function and Format method
// shows by example how the reference time should be represented.
// We stress that one must show how the reference time is formatted,
// not a time of the user's choosing. Thus each layout string is a
// representation of the time stamp,
// Jan 2 15:04:05 2006 MST
// An easy way to remember this value is that it holds, when presented
// in this order, the values (lined up with the elements above):
// 1 2 3 4 5 6 -7
{{ .Date.Format "Jan 2, 2006" }} becomes “Oct 4, 2007”
{{ .Date.Format "Jan 02, 2006" }} becomes “Oct 04, 2007”
https://www.madboa.com/blog/2016/08/24/hugo-dateformat/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment