Reputation: 401
I have been having an issue getting the right time to be saved in my database. If I do SELECT NOW() in postgres I will get the right time in EDT. When I do a Time.now in the ruby console I get the correct time as well. I can even take what I get from Time.now and manually copy/paste it and save it to the database through psql and it will be right. The problem is when I try to save the time in code, the time will jump to 3 or 4 hours ahead.
If anyone needs to see exactly what I get from Time.now or SELECT NOW() let me know and I'll post it when I get home.
I'm sure there is something small I'm overlooking, but I cannot figure it out! I'm guessing this may be a common issue for people setting up Ruby on Rails with postgres. Thanks for the help.
Upvotes: 0
Views: 950
Reputation: 6862
Rails 3 by default saves all the time in database relative in GMT+00:00 time zone. So you will have to set an offset while computing time depending on your timezone. Else, you can change default Activerecord time zone by adding following to application.rb
config.time_zone = 'Your time zone' (Example: 'Eastern Time (US & Canada)')
config.active_record.default_timezone = 'Your time zone' (Example: 'Eastern Time (US & Canada)')
Upvotes: 1