Time Zone issues on Heroku

I’ve run into this problem before and want to document the simple way that I finally fixed it.

I have Van model with a column called ‘departure_time’ in a Rails app this is a DateTime object. When a user/admin edits a van, they have a series of dropdowns to select the datetime using the datetime_select helper in Rails. Everything seems to be fine until I push to heroku, and then whenever I create a new van, or edit one, time time that I choose gets changed by 6 hours. I spend hour trying to figure this out on another app, and finally came across this simple solution:


I was using the bootstrap3-datetimepicker gem, which formats the datetime differently than what needs to go in the database, so I had to do some logic to parse that string into an acceptable datetime object, and then create a DateTime object with Time.new or Time.local.

Well, all I need to do to fixe the error is use Time.zone.local instead of Time.local. It now works locally and on Heroku.


About Aaron Glasenapp

I am a freelance Web/Rails developer and a hard core recreational mathematician.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: