Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 874
letz Avatar asked Jun 22 '16 18:06

letz


1 Answers

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

Example:

around_action :set_time_zone, if: :current_user

private

def set_time_zone(&block)
   Time.use_zone(current_user.time_zone, &block)
end
like image 64
letz Avatar answered Sep 19 '22 15:09

letz