views:

32

answers:

1

For example, I need to convert time from UTC to local. And I use Time.zone to do this.

1.Time.zone = local_zone_name
2.Time.zone.utc_to_local(utc_time_var)

But I'd like to avoid the usage of the first line since I believe this approach modifies the class variable. Any suggestions? Thx in advance!

+2  A: 

You can change the zone of any time like this:

t = Time.now                # gets local time
t.in_time_zone("UTC")       # converts to UTC
t.in_time_zone("Auckland")  # converts to Auckland time
Alex Reisner