There is an unknown issue with timezones related to Go Lang (see: https://community.cloudflare.com/t/hugo-timezone-format-issue/390678/12) (it’s also happening on Netlify). Check the following threads:
There are two workarounds:
Workaround 1: Set timezone var in CF Pages
See @jmooring’s screenshot.
Only catch, if you want to display different timezones (for example, for different languages), this will mess things up with the other timezones. The timezone you set in CF Pages is fixed. If you set it, everything will be in that timezone.
Workaround 2: edit your layout files
Add this in your layout files where the date / time is publicly displayed: {{ time.Format 2006-01-02T15:04:05Z07:00 (.PublishDate.UTC.Add (time.ParseDuration $.Site.Language.Params.tzOffset)) }}
By using Hugo’s / GoLang’s .UTC
, the post dates are automatically calculated to UTC time. From there, the .Add
feature in combination with time.ParseDuration
will add/subtract additional hours based on the value of $.Site.Language.Params.tzOffset
.
So, if you want a post (or another language) to display its local timezone, just set the post’s frontmatter to the correct one, say: date: 2023-01-27T01:09:51+09:00
.
The value for the $.Site.Language.Params.tzOffset
is based on what you’ve included in your [languages]
config section. It’s custom, so just add a new param tzOffset
per language.
You should have something like this:
{{ if not .PublishDate.IsZero }}<time datetime="{{ .PublishDate.UTC.Format "2006-01-02T15:04:05Z07:00" }}">{{ time.Format 2006-01-02T15:04:05Z07:00 (.PublishDate.UTC.Add (time.ParseDuration $.Site.Language.Params.tzOffset)) }}</time>{{ end }}
Here is what’s on my site: layouts/_default/header.html · main · YourOnly.One / site.snoworld · GitLab. And the live version is at: (en) Snoworld ❄️; (ja) 雪の世界 ❄️; (ko) 스노우 월드 ❄️.
You’ll see that the timezones are displayed correctly per language while I’m hosted on CF Pages. If you want to check the frontmatter for my posts, see: content/snoworld at main - content - Codeberg.org.
