DEV Community

Cover image for Time Zone issue with Heroku
Bhavesh Kasturi
Bhavesh Kasturi

Posted on • Updated on

Time Zone issue with Heroku

I've been using Heroku for a while now, Recently I was working on a project which was a basic chat application, It was built with Nodejs, socket.io, momentjs.

As it was a chat application I used momentjs for the timestamps on the messages, Everything was working fine locally, but when I deployed my app on Heroku I found that messages were not showing the correct time.

As the Heroku's default region is set to US & I was from India that was causing the issue. So basically momentjs was showing US Timezone.

So the problem was with Heroku's Timezone & Luckily Heroku allows us to change the timezone of our app just by simply adding a new config var.
After fixing the problem it was working fine :)

Here's the Solution:

Heroku Dashboard - Website

1- Login into the Heroku from a browser
2- Select your app
3- Go to the setting tab
4- Press "Reveal Config vars" button
5- Set the keys to "TZ" and value of your timezone (Eg: Asia/Kolkata)
6- Press the add button

Heroku CLI

1- Open your Command shell
2- Login into Heroku
3- cd into your App directory
4- Setup TZ

heroku config:add TZ="Asia/Kolkata"
Enter fullscreen mode Exit fullscreen mode

What is correct TZ value of your country ?

You can find your country's TZ value from this wiki page

India uses a single time zone for the whole country.
I looked on the Wiki page List of tz database time zones, but I was unable to find an entry for India.

If you can't find your country's TZ follow this link

Thanks for reading!

Top comments (1)

Collapse
 
duhbhavesh profile image
Bhavesh Kasturi

Glad it helped :)