Created
August 14, 2008 17:54
-
-
Save tamalw/5458 to your computer and use it in GitHub Desktop.
Get the time in another timezone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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