DEV Community 👩‍💻👨‍💻

Cover image for Change the time zone on a Heroku app
Paula Santamaría
Paula Santamaría

Posted on • Updated on

Change the time zone on a Heroku app

I discovered Heroku a few weeks ago. It's a great platform to deploy your apps, specially because of their Free plan which I've been using as dev env to work with my team remotely.

Lately I started working on a new project. On this particular project I rely on dates for most of the main operations. The app has a front-end built with Angular 5, and a back-end built with Node.js

Everything was working perfectly on my local environment, but when I deployed to Heroku all the date operations started to behave kind of random (spoilers: it wasn't random at all).

Well, here's the thing. I'm from Argentina, and I had the front-end deployed on a local server, but the back-end was on Heroku and the default region for new heroku apps is "us". So basically my front-end and back-end were on different time zones.

This is not the first time I deal with this kind of date issues (there aren't many local cloud services in my region) so I found the source of the problem almost immediately, and I wanted to share it with you in case you encounter a similar issue.

Luckily Heroku let's us change the timezone of our app simply by adding a new config var.

From the Heroku CLI

  1. Open the command shell
  2. Login to heroku
  3. Navigate to your app's directory
  4. Setup your TZ
heroku config:add TZ="America/Argentina/Buenos_Aires"
Enter fullscreen mode Exit fullscreen mode

From the Heroku dashboard (web)

  1. Login into the Heroku dashboard from a browser
  2. Navigate to the app
  3. Click over the Settings tab
  4. Press the "Reveal Config Vars" button
  5. Set the key to "TZ" and the value to your timezone (E.g.: America/Argentina/Buenos_Aires)
  6. Press the Add button

How do I know which is the correct TZ value

Follow this link to see the complete list of time zones

Check the new TZ value

Use the following command to check the value of the new config var from Heroku CLI:

heroku config:get TZ
Enter fullscreen mode Exit fullscreen mode

For more info about Heroku

What is Heroku?

For more info about Heroku's Config Vars

Configuration and Config vars

Top comments (34)

Collapse
 
mguimaraes16 profile image
Marcello Guimarães

Paula, you are a hero, I didn't realize that would be so easy, I was about to change my.net core api to get my Timezone(Brazil) and let be honest, it would be a headache, and it wasn't necessary, Thank you!!

Collapse
 
paulasantamaria profile image
Paula Santamaría Author

Glad I could help :D and thanks for reaching out!

Collapse
 
brett84c profile image
Brett Connolly • Edited on

Hell yes! You saved me a heart attack. I couldn't figure out why my app that just went live was being screwy with the dates despite my testing and live environments being connected to the same database. Thank you!

Collapse
 
paulasantamaria profile image
Paula Santamaría Author

Timezone issues are a nightmare! Glad I could help :)

Collapse
 
vjnvisakh profile image
Visakh Vijayan

Thank you so much

Collapse
 
xanthisafk profile image
Abhinav

Thank you very much! 👍

Collapse
 
lafriedel profile image
Leigh-Ann Friedel

Thank you so much for this article! I'm building an app with a small team and we have been fighting with getting proper dates to display. It's consistently been one day behind. This fixed it!

Collapse
 
paulasantamaria profile image
Paula Santamaría Author

Glad I could help! :)

Collapse
 
felipealvarez23 profile image
felipealvarez23

Thank you men, It worked

Collapse
 
azhariemuhammad profile image
Muhammad Amri A. Azhary • Edited on

Many thanks.

Collapse
 
paulasantamaria profile image
Paula Santamaría Author

Happy to help!

Collapse
 
greegav profile image
Andrii Hryhoriev

Many thanks for this advice!
It is REALLY helpful.
Good Luck!

Collapse
 
paulasantamaria profile image
Paula Santamaría Author

You're welcome!

Collapse
 
awelle profile image
Awelle

This just ended my 3-day heartache. Literally. Thank you for sharing.

Collapse
 
paulasantamaria profile image
Paula Santamaría Author

I'm glad! Thanks for letting me know :)

Collapse
 
princebillygk profile image
Prince Billy Graham Karmoker • Edited on

Very useful thanks

Collapse
 
kk007 profile image
Keval navadiya

If I just add TZ config and I am doing something which requires system time will it use timezone set by using the TZ ?

Collapse
 
paulasantamaria profile image
Paula Santamaría Author

Yes, that's how it usually works. I'm not sure if there are any specific cases where that's not the case.

For example, if you deploy a node.js app that does something like var now = new Date(), it will use the timezone you specified in your TZ config.

Collapse
 
monishbasaniwal profile image
Monish Basaniwal

Time is a complex thing, and Paula you helped me out today. I never imagined it to be soo easy!

Collapse
 
paulasantamaria profile image
Paula Santamaría Author

I'm glad, Monish!

Collapse
 
raxraj profile image
ASHUTOSH KUMAR

Saved my little ar**!! Can't thank you enough Buddy!

Collapse
 
sinisimattia profile image
Mattia Sinisi

2 years later and this article is STILL useful

Collapse
 
paulasantamaria profile image
Paula Santamaría Author

Thanks Mattia, glad to hear that :)

Collapse
 
confusedcoder1 profile image
Shristi Singh

I really was calculating times to adjust them, when I found this. I thought as regions are permanent timezones must be too. But huh. You saved me. Thanksss.

Collapse
 
madza profile image
Madza

Thanks, just found it useful 😉👍

Collapse
 
ysoul801 profile image
ysoul801 • Edited on

I can't thank you enough ! just signed up to leave a comment (maybe more use in future d: )

Collapse
 
paulasantamaria profile image
Paula Santamaría Author

Glad to help! Also, you won't regret signing up to this platform :)

Collapse
 
naothomachida profile image
Naotho Machida

Thanks! Solved

Collapse
 
gerocoded profile image
Luis Gerónimo

¡Muchas gracias! Me ayudaste en mi proyecto de tesina.

Collapse
 
paulasantamaria profile image
Paula Santamaría Author

Me alegro!

Collapse
 
luchorivas profile image
Luis

Sos muy crack Pau

Collapse
 
paulasantamaria profile image
Paula Santamaría Author

jajaja justo te iba a decir que no me habias dejado un comentario. Gracias, green mario.

Collapse
 
shashankojhabot profile image
Shashank Ojha • Edited on

Thanks for Posting this.
It really helped.

Collapse
 
nirajsharma99 profile image
nirajsharma99

Thankyou so much this saved much of my time. You are awesome ;)

🌚 Friends don't let friends browse without dark mode.

Just kidding, it's a personal preference. But you can change your theme, font, etc. in your settings.

The more you know. 🌈