How can I set timezone in simple form datetime field?

亡梦爱人 提交于 2019-12-10 14:58:52

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/37975594/how-can-i-set-timezone-in-simple-form-datetime-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!