letz letz - 1 year ago 99
Ruby Question

How can I set timezone in simple form datetime field?

I have a model with a datetime field, and is stored in UTC, how can I display that date in simple form gem in a specific timezone?

Already tried with the option

input_html: {value: @model.date.in_time_zone('Eastern Time (US & Canada)')}

Note: I can't change the timezone of rails app

Answer Source

It will work if you set the timezone in the controller:


around_action :set_time_zone, if: :current_user


def set_time_zone(&block)
   Time.use_zone(current_user.time_zone, &block)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download