Flexo
Flexo

Reputation: 2556

Rails timezone is wrong when shown

I have a problem when showing a datetime object from the database. The time is correctly set in when storing the object, but when it is fetched from db and shown to user it is shown in UTC

environment.rb

config.time_zone = 'Copenhagen'

This is what is saved using Time.now or Time.zone.now

2010-07-08 13:59:50 +0200

This is what is shown to the user when using the html helper <%=h ff.date_registered %> 2010-07-08 11:59:50 UTC

Upvotes: 3

Views: 4188

Answers (1)

Mike
Mike

Reputation: 1684

Try Time.current. Time.now is returned in UTC -5 always. ActiveRecord instructs Time.current based on your config.time_zone. See this github issue for more information, https://github.com/rails/rails/issues/3128#issuecomment-2195751

Upvotes: 1

Related Questions