如何在简单形式的datetime字段中设置时区? [英] How can I set timezone in simple form datetime field?
本文介绍了如何在简单形式的datetime字段中设置时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有日期时间字段的模型,并存储在UTC中,如何在特定时区中以简单形式的gem显示该日期?
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?
已经尝试使用选项input_html: {value: @model.date.in_time_zone('Eastern Time (US & Canada)')}
注意:我无法更改Rails应用的时区
Note: I can't change the timezone of rails app
推荐答案
如果您在控制器中设置了时区,它将起作用:
It will work if you set the timezone in the controller:
示例:
around_action :set_time_zone, if: :current_user
private
def set_time_zone(&block)
Time.use_zone(current_user.time_zone, &block)
end
这篇关于如何在简单形式的datetime字段中设置时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文