How to render timezone names in templates?

I’m trying to create a template, where the timezone name is rendered correctly for every post and I don’t see a way to make it work the way I want it.

For this post, written in Bali lately, date:

date: 2016-10-28T17:28:09+08:00

I have the output set to:

{{ .Date.Format "January 2, 2006 15:04 MST" }}

and I’d like it to render:

Friday, October 28, 2016 17:28 WITA

but instead it does:

Friday, October 28, 2016 17:28 +0800

at least right now, when I’m sitting in Warsaw in the CE(S)T timezone. The funny thing is, the template did render the timezone name when I was running it back in Bali, where the date above was rendering to:

Friday, October 28, 2016 17:28 SGT

(SGT is Singapore time; WITA is the same time offset but for central Indonesia).

Now to the questions:

  1. Why does the template render the acronym of the timezone only for the current timezone I’m in at the moment? Can I force it to render all acronyms?
  2. Can I force it to render the correct acronym? Ie. WITA instead of SGT?

I can’t see anything in Go’s time documentation on this and right now the only solution I found is to enter the timezone manually into the post’s meta:

date: 2016-10-28T17:28:09+08:00
timezone: WITA
1 Like

For time formats you can look at the page time integration tests for examples and counter-examples: here and there.

But I don’t know if it will help solving your problem!

Three days later looks like I posted a really tough questions with so many views and so few replies :slight_smile: Thanks @lebarde, I couldn’t see anything in the pieces of code you provided, that would help me.

So, for posterity, here’s what I’m doing right now to get around the issue.

In my content:

date: 2016-10-28T17:28:09+08:00
timezone: WITA

and in my template, a conditional check on whether the timezone field is available:

{{ .Date.Format "Monday, January 2, 2006 15:04" }} {{ if isset .Params "timezone" }}{{ .Params.timezone }}{{ else }}{{ .Date.Format "MST" }}{{ end }}

Any suggestions for improvements on this would me most welcome.

@mpaluchowski I played around with this locally but to no avail, although it looks like there is a way to add the time zone name via go date formatting (

This isn’t the ideal solution you’re looking for, but moment timezone might help you on the client…


If you’re seasoned in Golang: