Skip to content

Instantly share code, notes, and snippets.

@tamalw
Created August 14, 2008 17:54
Show Gist options
  • Save tamalw/5458 to your computer and use it in GitHub Desktop.
Save tamalw/5458 to your computer and use it in GitHub Desktop.
Get the time in another timezone
require 'time'
class Time
def in(tz)
current_tz = ENV["TZ"]
ENV["TZ"] = tz
new_time = self.getutc.getlocal
ENV["TZ"] = current_tz
new_time
end
end
t = Time.now # => Thu Aug 14 10:55:24 -0700 2008
t.in("US/Eastern") # => Thu Aug 14 13:55:24 -0400 2008
t # => Thu Aug 14 10:55:24 -0700 2008
t.in("US/Central") # => Thu Aug 14 12:55:24 -0500 2008
t # => Thu Aug 14 10:55:24 -0700 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment