In my application.rb
I came across the following comment
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
config.time_zone = 'Eastern Time (US & Canada)'
As you see from above, I've made config.time_zone
to EST time. However, still when records are created in the DB, it looks like datetime
is being stored in UTC format.
In the above comment, they say
...and make Active Record auto-convert to this zone...
How can I do that, and where?
Also, I'll be deploying this on heroku as well and i'd like the setting to carry over
I have decided to compile this answer because all others seem to be incomplete.
If you want to change Rails timezone, but continue to have Active Record save in the database in UTC, use
If you want to change Rails timezone AND have Active Record store times in this timezone, use
Warning: you really should think twice, even thrice, before saving times in the database in a non-UTC format.
Remember that
config.active_record.default_timezone
can take only two valuesconfig.time_zone
)Here's how you can find all available timezones
I came to the same conclusion as Dean Perry after much anguish.
config.time_zone = 'Adelaide'
andconfig.active_record.default_timezone = :local
was the winning combination. Here's what I found during the process.On rails 4.2.2, go to
application.rb
and useconfig.time_zone='city'
(e.g.:'London' or 'Bucharest' or 'Amsterdam' and so on).It should work just fine. It worked for me.
adding following to
application.rb
worksIf you want local time to set, add the following text in
application.rb
Then restart your server
If you want to set the timezone to UTC globally, you can do the following in Rails 4:
Be sure to restart your application or you won't see the changes.