Formatting dates in Hugo
How Hugo date formatting works, from Go's reference-time layouts to localized output and time zones, plus readability, accessibility and copy/paste tradeoffs.
Hugo does not use the familiar YYYY-MM-DD style of date patterns. It formats dates using Go's reference-time layouts, which confuses many people the first time they change how a post date appears. This review explains what Hugo's date formatting changes, how to choose a layout that stays readable for a US audience and others, and when a plain written date is the better choice. It is based on documented Hugo and Go behavior. No hands-on tests were run for this article, and the gaps are noted where they matter.
What Hugo date formatting actually changes
Formatting a date in Hugo is a build-time text transformation. The date in your front matter, such as date, publishDate, lastmod or expiryDate, is read into a time value. Templates then turn that value into a string. The stored front matter value does not change. Only the rendered text in the generated HTML is affected. The result is ordinary characters in a static file. It is not CSS styling, not a font effect and not a visual trick. Whatever the template prints is exactly what browsers, crawlers, screen readers and copy/paste operations receive.
Because the output is fixed when the site is built, any date that depends on the current moment, such as "3 days ago," stays frozen until the next build. This is the main structural tradeoff of formatting dates on a static site.
How Go's reference-time layouts work
Instead of placeholder letters, a Hugo layout string is written as a sample rendering of one specific moment: Monday, January 2, 2006 at 3:04:05 PM, in the MST zone, offset -0700. Each component of that moment acts as a token. Writing 2006 means "four-digit year," 01 means "zero-padded month," Jan means "abbreviated month name," and so on. Anything that does not match a token is printed literally.
| Token | Meaning | Example output for March 5, 2024, 2:30 PM |
| 2006 | Four-digit year | 2024 |
| 06 | Two-digit year | 24 |
| January | Full month name | March |
| Jan | Abbreviated month name | Mar |
| 01 | Zero-padded month number | 03 |
| 1 | Month number without padding | 3 |
| 02 | Zero-padded day | 05 |
| 2 | Day without padding | 5 |
| Monday | Full weekday name | Tuesday |
| Mon | Abbreviated weekday name | Tue |
| 15 | Hour, 24-hour clock | 14 |
| 3 | Hour, 12-hour clock | 2 |
| 04 | Minutes | 30 |
| PM | AM/PM marker | PM |
| MST | Time zone abbreviation | Depends on the zone |
| -0700 | Numeric zone offset | Depends on the zone |
The page methods apply a layout directly. The examples below assume a page dated March 5, 2024 at 2:30 PM. The outputs follow from the layout rules above, not from a captured build.
{{ .Date.Format "January 2, 2006" }} → March 5, 2024
{{ .Date.Format "Jan 2, 2006" }} → Mar 5, 2024
{{ .Date.Format "2006-01-02" }} → 2024-03-05
{{ .Date.Format "Monday, January 2, 2006 at 3:04 PM" }} → Tuesday, March 5, 2024 at 2:30 PM
A layout like "YYYY-MM-DD" does not raise an error. Those letters are not tokens, so they print literally. If the rendered page shows something odd instead of a date, check the layout first.
Localized output with time.Format
The .Format method on a date uses Go's own formatting, which produces English month and day names. Hugo's time.Format function (also available as dateFormat) accepts the same layouts but localizes month and weekday names according to the current site language. It also accepts predefined localized layouts: :date_full, :date_long, :date_medium and :date_short for dates, and matching :time_ variants for times. With these, the order and punctuation follow the language's conventions instead of a hand-written layout.
{{ time.Format ":date_long" .Date }}
{{ .Date | time.Format ":date_medium" }}
{{ time.Format "January 2, 2006" .Date }}
The exact text these localized layouts produce depends on the language configured for the site or page. This article does not show sample outputs for them because none were verified. On a multilingual site, preview each language before relying on a particular layout.
Time zones
A front matter date without an offset is interpreted in the site's configured time zone, which defaults to UTC. Set timeZone in your site configuration if your dates should be read in a local zone. Otherwise a post published late in the evening in the US can render with the next day's date. Including an explicit offset in front matter removes the ambiguity for that page.
# hugo.toml
timeZone = "America/New_York"
Will the formatted date stay readable after copying or sharing?
Since the output is plain text, it copies and pastes as plain text. It also stays editable, searchable and selectable like any other words on the page. The readability risks come from the layout you choose, not from the mechanism.
- Numeric dates are ambiguous across regions. 03/05/2024 reads as March 5 in the US but as 3 May in many other countries. Spelling out the month avoids this for human readers.
- ISO style (2006-01-02) is unambiguous and sorts correctly, but some general readers find it less natural than a written-out date.
- Abbreviations such as Mar or Tue are compact but less clear than full names when the date is read aloud or seen out of context.
- Ordinal suffixes such as 5th are not a Go layout token. You can build them with Hugo's humanize function, but they add template complexity.
- Relative phrases such as "2 days ago" become wrong after the build unless you add client-side scripting.
For pages that need to be both human-readable and machine-readable, wrap the visible date in an HTML time element with a full timestamp in its datetime attribute. The visible text stays friendly, while the attribute gives browsers, feed readers and crawlers an unambiguous value.
<time datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}">
{{ .Date.Format "January 2, 2006" }}
</time>
{{ .Date.Format "January" }} {{ humanize .Date.Day }}, {{ .Date.Year }} → March 5th, 2024
When copying text, people generally get the visible text, not the datetime attribute, so the visible layout should be able to stand on its own. Screen readers typically announce the visible text. How a particular screen reader pronounces abbreviations, numeric dates or the time element was not tested for this article. If accessibility is a priority, test with the assistive technology your audience uses, and favor full month names in the meantime.
Common mistakes
- Using placeholder letters (YYYY, MM, DD) instead of reference values, which prints them literally.
- Writing 1 or 01 where the day was intended. 1 and 01 mean month, while 2 and 02 mean day.
- Using 15 for the hour alongside PM. 15 is the 24-hour clock, while 3 is the 12-hour clock.
- Expecting .Date.Format to localize month names. Use time.Format for that.
- Leaving timeZone unset and getting off-by-one dates near midnight.
- Repeating the same layout string across many templates instead of putting it in a partial, which makes later changes error-prone.
Is Hugo date formatting the right approach for your site?
For almost any date that comes from front matter, formatting it in templates is the right choice. The main benefit is consistency: one layout controls every page, and the output is plain, copyable, accessible text. The decisive tradeoff is that the output is fixed at build time. Relative or "time since" displays go stale, and localized layouts depend on your language configuration being correct.
A plain written date in the content itself is preferable in a few cases. One is when the date is not structured data at all, such as "Spring 2024" or a historical reference. Another is a one-off page where wording matters more than consistency. A third is any case where the exact phrasing must not change when templates are edited later. A reasonable default for a US-facing site is a written-out layout such as "January 2, 2006" for display, wrapped in a time element with a full ISO timestamp. Switch to time.Format with a localized layout once the site serves more than one language.
What this review could not verify
No builds, browser renderings or assistive-technology tests were performed for this article. The sample outputs are derived from Go's documented layout rules, not captured from a running site. The exact text of localized layouts for specific languages, and the Hugo version in which particular functions or options were introduced, are not stated here. Check the documentation for the version you use if your site runs an older release.