3

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

Flexo
  • 2,506
  • 3
  • 21
  • 32

1 Answers1

1

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

Mike
  • 1,626
  • 1
  • 12
  • 14