time.Format working when built locally, but not when built on Netlify

I’m using time.Format to format a date on my blog posts.
It renders correctly on my local machine, but does not when using Netlify’s continuous deployment.

I think it might be that time.Format relies on the machine’s time zone setting and it’s not configured on the build server. I have tried setting the timeZone parameter in the site’s config.toml. That didn’t work. I tried setting an environment variable in the netlify dashboard (TZ=‘America/Detroit’). That didn’t work.

I’ve seen some stuff saying I might need to do something in a netlify.toml file, but I haven’t tried that because I couldn’t find anything that looked like what I needed (or that would be different from just setting the environment variable in Netlify.)

Can anybody point me in the right direction?

Source repo: GitHub - schaefsteven/cn-hugo

Blog post on live site where you can see the problem: https://commonnonsense.netlify.app/blog/blog-1/

Netlify needs TZ=PST8PDT / TZ=EST5EDT style timezones, not the TZ=America/Detroit style.

Or maybe not, see Joe’s point about version. I know the example on the Netlify forum uses the format I mentioned:

To localize dates you need v0.87.0 or later. You’re building with v0.85.0 on Netlify.

1 Like

I believe that was the solution. Thank you! I wouldn’t have thought that the default version would be that far behind.

For anyone who runs into this and finds this post in the future, you need to specify a more recent version either in netlify.toml or in the Netlify console. See this part of the docs: https://gohugo.io/hosting-and-deployment/hosting-on-netlify/#configure-hugo-version-in-netlify

Special thanks to you folks on here by the way at being so helpful and also VERY quick to answer questions. Joe, you have answered a couple of things that I have gotten stuck on now, and it’s very encouraging to someone learning. I appreciate you all and keep up the fantastic work!



These are not the same thing:

  • America/Los_Angeles

But you can use either on Netlify. I would always use the later.

1 Like

Thanks. I was confused on that.

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