The following code converts the
“time” to new “timezone value”.
Paste the following code in the application.rb or wherever you like
def convert_zone(to_zone)
#notify the current timezone
original_zone = ENV[”TZ”]
#finds UTC time
utc_time = dup.gmtime
#change the zone into the requested zone(parameter
value)
ENV[”TZ”] = to_zone
#convert the UTC time to local time in the changed
zone
to_zone_time = utc_time.localtime
#Now change the zone back to the original zone
ENV[”TZ”] = original_zone
return to_zone_time
end
This function takes the “timezone”(to which you want to convert) as a
parameter and takes control of the rest.
(Eg.)
t = Time.now
# => Sun Sep 09 01:46:40 UTC 2001
t.convert_zone(”Asia/Calcutta”) # => Sun Sep 09
07:16:40 IST 2001