# How to display time by timezone?

**URL:** <https://discourse.gohugo.io/t/how-to-display-time-by-timezone/42643>\
**Category:** support\
**Created:** [January 27, 2023, 1:49am UTC](https://discourse.gohugo.io/t/how-to-display-time-by-timezone/42643 "2023-01-27T01:49:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![hzb](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@hzb](https://discourse.gohugo.io/u/hzb)\
**Post date:** [January 27, 2023, 1:49am UTC](https://discourse.gohugo.io/t/how-to-display-time-by-timezone/42643/1 "2023-01-27T01:49:23Z")

</div>

Hello all,

I create a new post via `hugo new post/test.md`

```auto
---
date: 2023-01-27T01:09:51+08:00
---

```

`2023-01-27T01:09:51` is UTC+0 and `+08:00` is my current timezone.

I try to display it on page via `{{ .Date | time.Format "2006-01-02 15:04:05" }}` and it shows the results as `2023-01-27 01:09:51`, but I want it to display according to my current time zone, like `2023-01-27 09:09:51`.

How? Thank you so much.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [January 27, 2023, 2:46am UTC](https://discourse.gohugo.io/t/how-to-display-time-by-timezone/42643/2 "2023-01-27T02:46:23Z")

</div>

> [@hzb](#):
>
> `2023-01-27T01:09:51` **is UTC+0**

Then the fully qualified time stamp should be:

```plaintext
2023-01-27T01:09:51-00:00

OR

2023-01-27T01:09:51Z

```

To display the local time equivalent:

```auto
{{ .Date.Local.Format "2006-01-02 15:04:05" }}

OR

{{ .Date.Local | time.Format "2006-01-02 15:04:05" }}

```

---

<div class="post-metadata">

**Author:** ![hzb](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@hzb](https://discourse.gohugo.io/u/hzb)\
**Post date:** [January 28, 2023, 12:09am UTC](https://discourse.gohugo.io/t/how-to-display-time-by-timezone/42643/3 "2023-01-28T00:09:57Z")

</div>

Hello, thank you so much for the reply, but it is still strange.

I updated the date to `2023-01-27T01:09:51Z`, and also use local time equivalent. `{{ .Date.Local | time.Format "2006-01-02 15:04:05" }}`

And the time it should display is `2023-01-27 09:09:51`, but actually I get `2023-01-26 15:09:51`.

My local timezone is `+08:00`, not `-08:00`.

Thank you.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [January 28, 2023, 12:14am UTC](https://discourse.gohugo.io/t/how-to-display-time-by-timezone/42643/4 "2023-01-28T00:14:05Z")

</div>

Which operating system?

---

<div class="post-metadata">

**Author:** ![hzb](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@hzb](https://discourse.gohugo.io/u/hzb)\
**Post date:** [January 28, 2023, 12:25am UTC](https://discourse.gohugo.io/t/how-to-display-time-by-timezone/42643/5 "2023-01-28T00:25:08Z")

</div>

CloudFlare pages.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [January 28, 2023, 12:29am UTC](https://discourse.gohugo.io/t/how-to-display-time-by-timezone/42643/6 "2023-01-28T00:29:27Z")

</div>

You need to set the TZ to “Asia/Singapore” in your Cloudflare build settings. This is not a Hugo issue.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [January 28, 2023, 12:49am UTC](https://discourse.gohugo.io/t/how-to-display-time-by-timezone/42643/7 "2023-01-28T00:49:04Z")

</div>

This screen capture may be helpful. Not sure how old it is…

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/8/5/85da86d68857b6aa7ae8a6e59b19b121383d9687.png)

---

<div class="post-metadata">

**Author:** ![hzb](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@hzb](https://discourse.gohugo.io/u/hzb)\
**Post date:** [January 28, 2023, 7:58am UTC](https://discourse.gohugo.io/t/how-to-display-time-by-timezone/42643/8 "2023-01-28T07:58:23Z")

</div>

> [@jmooring](#):
>
> You need to set the TZ to “Asia/Singapore” in your Cloudflare build settings. This is not a Hugo issue.

I see, thank you so so much.

---

<div class="post-metadata">

**Author:** ![techmagus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/techmagus/32/16997_2.png) [@techmagus](https://discourse.gohugo.io/u/techmagus)\
**Post date:** [January 30, 2023, 2:22am UTC](https://discourse.gohugo.io/t/how-to-display-time-by-timezone/42643/9 "2023-01-30T02:22:08Z")

</div>

There is an unknown issue with timezones related to Go Lang (see: [https://community.cloudflare.com/t/hugo-timezone-format-issue/390678/12](https://community.cloudflare.com/t/hugo-timezone-format-issue/390678/12)) (it’s also happening on Netlify). Check the following threads:

- [MST showing as +0900 instead of the "MST" value](https://discourse.gohugo.io/t/bug-mst-showing-as-0900-instead-of-the-mst-value/37883)
- [https://community.cloudflare.com/t/hugo-timezone-format-issue/390678](https://community.cloudflare.com/t/hugo-timezone-format-issue/390678)
- [https://community.cloudflare.com/t/re-timezone-format-issue/391130/5](https://community.cloudflare.com/t/re-timezone-format-issue/391130/5)

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:

```auto
{{ 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](https://gitlab.com/youronlyone/site.snoworld/-/blob/main/layouts/_default/header.html). And the live version is at: (en) [Snoworld](https://im.youronly.one/snoworld/); (ja) [スノーワールド](https://im.youronly.one/snoworld/ja/); (ko) [스노우월드](https://im.youronly.one/snoworld/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: [Making sure you're not a bot!](https://codeberg.org/youronlyone/content/src/branch/main/snoworld).

🙂

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [February 1, 2023, 2:22am UTC](https://discourse.gohugo.io/t/how-to-display-time-by-timezone/42643/10 "2023-02-01T02:22:15Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
