Rails change default timezone

偶尔善良 提交于 2019-12-11 14:09:38

问题


I'm trying to change default timezone in Rails 3.2.8 app to GMT+04:00, but I don't know how to do it. The following solutions do not work for me:

config.time_zone = 'Moscow'
config.time_zone = "(GMT+04:00) Moscow"
config.active_record.default_timezone = 'Moscow'
config.active_record.default_timezone = :local

Also I've tried in rails console the following: ActiveSupport::TimeZone.all.map(&:name) wich returned a list of values, including "Moscow". Time.zone returned (GMT+00:00) UTC wich is not correct, it should be (GMT+04:00) UTC. Then I changed Time.zone = "Moscow" and Time.now returned the correct value (... +0400).

So to fix it I simply used Time.now + 4.hour, but I also need datetime_select to display my local time. Time.now + 4.hour is not a correct solution.

Please, share any ideas how one can set default time zone to his local value. Thank you in advance.


回答1:


All of a sudden I've localized the problem. I run Win7 and my WEBrick server is showing the correct time, but the project itself shows a wrong one. In the same time, my production server is working correctly, so, obviously, the problem is with the OS. UPD: The problem is fixed. I should have restarted the WEBrick server after changing the application.rb file.



来源:https://stackoverflow.com/questions/13752810/rails-change-default-timezone

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