如何在Rails中设置时区?

时间:2019-06-04 00:17:28

标签: ruby-on-rails ruby timezone

我在铁路上工作,我试图弄清楚如何设置时区,以便Time.now给我

Mon, 03 Jun 2019 19:08:13 CDT -05:00

1 个答案:

答案 0 :(得分:4)

尝试一下:

# application.rb

class Application < Rails::Application
  config.time_zone = 'Eastern Time (US & Canada)'
end

Time.zone      # => #<ActiveSupport::TimeZone:0x514834...>
Time.zone.name # => "Eastern Time (US & Canada)"
Time.zone.now  # => Sun, 18 May 2008 14:30:44 EDT -04:00

来源:https://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html