如何将时区更改为欧洲/阿姆斯特丹。 我尝试将以下内容放在application_controller.rb
中config.time_zone = "Europe/Amsterdam"
答案 0 :(得分:2)
您可以在config/application.rb
config.time_zone = 'Central Time (US & Canada)'
或强>
<强>的ApplicationController 强>
使用 @country 管理您要切换到的时区。 在此示例中,我使用“子域”来获取 @country 。您可以轻松适应您的场景
将此内容写入/app/controller/application_controller.rb
class ApplicationController < ActionController::Base
before_filter :set_country
before_filter :set_time_zone
private
def set_country
if request.subdomains.empty? || request.subdomains.first == 'www'
redirect_to(:subdomain => "uk")
else
@country ||= request.subdomains.first.upcase
end
@country ||= "IT"
end
def set_time_zone
case @country
when 'IT'
Time.zone = 'Rome'
when 'US'
Time.zone = 'Central Time (US & Canada)'
when 'UK'
Time.zone = 'London'
end
end
end
答案 1 :(得分:0)
您可以在config/application.rb
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'