Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ ruby -e 'puts Time.now'
- Sat Jan 15 20:49:10 -0800 2011
- $ TZ=UTC ruby -e 'puts Time.now'
- Sun Jan 16 04:49:20 +0000 2011
- def with_time_zone(tz_name)
- prev_tz = ENV['TZ']
- ENV['TZ'] = tz_name
- yield
- ensure
- ENV['TZ'] = prev_tz
- end
- >> with_time_zone('US/Eastern') { puts Time.at(1000000000) }
- 2001-09-08 21:46:40 -0400
- >> with_time_zone('US/Pacific') { puts Time.at(1000000000) }
- 2001-09-08 18:46:40 -0700
- >> require 'active_support/time'
- => true
- >> Time.at(1000000000).in_time_zone('US/Eastern')
- => Sat, 08 Sep 2001 21:46:40 EDT -04:00
- >> Time.at(1000000000).in_time_zone('US/Pacific')
- => Sat, 08 Sep 2001 18:46:40 PDT -07:00
- >> ActiveSupport::TimeZone::MAPPING
- => => {"International Date Line West"=>"Pacific/Midway", "Midway Island"=>"Pacific/Midway", ...}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement