0

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.

3
  • What time are you trying to capture? Commented Mar 15, 2012 at 17:31
  • What does Time.zone.now give you? Commented Mar 15, 2012 at 17:32
  • Thu, 15 Mar 2012 22:34:30 UTC +00:00 I guess that is my problem Commented Mar 15, 2012 at 22:35

1 Answer 1

1

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)')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.