Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. $ ruby -e 'puts Time.now'
  2. Sat Jan 15 20:49:10 -0800 2011
  3. $ TZ=UTC ruby -e 'puts Time.now'
  4. Sun Jan 16 04:49:20 +0000 2011
  5.  
  6. def with_time_zone(tz_name)
  7. prev_tz = ENV['TZ']
  8. ENV['TZ'] = tz_name
  9. yield
  10. ensure
  11. ENV['TZ'] = prev_tz
  12. end
  13.  
  14. >> with_time_zone('US/Eastern') { puts Time.at(1000000000) }
  15. 2001-09-08 21:46:40 -0400
  16. >> with_time_zone('US/Pacific') { puts Time.at(1000000000) }
  17. 2001-09-08 18:46:40 -0700
  18.  
  19. >> require 'active_support/time'
  20. => true
  21. >> Time.at(1000000000).in_time_zone('US/Eastern')
  22. => Sat, 08 Sep 2001 21:46:40 EDT -04:00
  23. >> Time.at(1000000000).in_time_zone('US/Pacific')
  24. => Sat, 08 Sep 2001 18:46:40 PDT -07:00
  25.  
  26. >> ActiveSupport::TimeZone::MAPPING
  27. => => {"International Date Line West"=>"Pacific/Midway", "Midway Island"=>"Pacific/Midway", ...}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement