私はRubyを使っています。私はUTCをさまざまな時間変換に変換したい。私はリンクhereに従う。タイムゾーンを別のものに変換する
class TimeFormat
def convert_zone(to_zone)
original_zone = ENV["TZ"]
utc_time = dup.gmtime
ENV["TZ"] = to_zone
to_zone_time = utc_time.localtime
ENV["TZ"] = original_zone
return to_zone_time
end
end
t = TimeFormat.new
t.convert_zone("US/Pacific")
しかし、それは示しています:
私のコードがある
undefined method `gmtime' for #<TimeFormat:0x9043388> (NoMethodError)
ここで間違っては何ですか?