tamalw (owner)

Revisions

  • dd3910 firblitz Thu Aug 14 10:56:02 -0700 2008
  • bb3c04 firblitz Thu Aug 14 10:54:21 -0700 2008
gist: 5458 Download_button fork
public
Description:
Get the time in another timezone
Public Clone URL: git://gist.github.com/5458.git
Embed All Files: show embed
time_tz_monkeypatch.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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