我的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_name = ActiveSupport::TimeZone::MAPPING.keys.find do |name|
: uninitialized constant ActiveSupport::TimeZone (NameError)
有人知道怎么回事吗?我从Stack Overflow中获得了这个代码段,在这里
添加
require 'active_support/time_with_zone'