I’m working with Ruby. I want to convert UTC to various time conversion. I follow the link here.
My code is:
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")
But it shows:
undefined method `gmtime' for #<TimeFormat:0x9043388> (NoMethodError)
What’s wrong here?
If you get an error when calling ‘convert_zone’ saying “undefined method `gmtime'”, you are probably passing something instead of the required Time object as a parameter.
Here is something similar that you might looking for.
http://www.java2s.com/Code/Ruby/Time/Converttimetotimezone.htm
You can extend Time class and define your own method.