Ruby 未初始化的常量ActiveSupport::时区(NameError)

Ruby 未初始化的常量ActiveSupport::时区(NameError),ruby,timezone,Ruby,Timezone,我的Ruby脚本中有几行代码,可以获取当前日期(我的是GMT)并将其转换为ET(东部时间) 我的Ruby脚本中有以下代码: # get current time and date in ET my_offset = 3600 * -5 # US Eastern # find the zone with that offset zone_name = ActiveSupport::TimeZone::MAPPING.keys.find do |name| ActiveSupport::Ti

我的Ruby脚本中有几行代码,可以获取当前日期(我的是GMT)并将其转换为ET(东部时间)

我的Ruby脚本中有以下代码:

# get current time and date in ET
my_offset = 3600 * -5  # US Eastern

# find the zone with that offset
zone_name = ActiveSupport::TimeZone::MAPPING.keys.find do |name|
  ActiveSupport::TimeZone[name].utc_offset == my_offset
end
zone = ActiveSupport::TimeZone[zone_name]

time_locally = Time.now
time_in_zone = zone.at(time_locally)
问题是它在这里给出了一个错误(好的,在这一行):
zone\u name=ActiveSupport::TimeZone::MAPPING.keys.find do | name |
未初始化常量ActiveSupport::TimeZone(NameError)

有人知道怎么了吗?我从堆栈溢出中获得了这个代码段。

Add

require 'active_support/time_with_zone'

在您的其他需求之后。

您是否需要“rubygems”和该代码顶部的“active_support”?如果你不需要,你就需要它。是的,我的代码中有这些要求。仍然不起作用。这解决了这个错误,但现在它给出了一个新的错误:
/Library/Ruby/Gems/1.8/Gems/activesupport-3.0.0/lib/active\u support/values/time\u zone.rb:260:in at:12月15日17:43:18 UTC 2011:time(NoMethodError)来自Ruby评级。我的代码中的第35行是:
time\u in\u-in\u zone=zone.at(本地时间)