Last active
December 27, 2015 16:19
-
-
Save gouf/7353878 to your computer and use it in GitHub Desktop.
タイムゾーンの指定による時刻の変換
From http://d.hatena.ne.jp/tonkoh/20080901/1220287952
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
| class Time | |
| def convert_zone(to_zone) | |
| original_zone = ENV["TZ"] | |
| utc_time = dup.gmtime | |
| ENV["TZ"] = to_zone | |
| to_zone_time = utc_time.localtime | |
| ENV["TZ"] = original_zone | |
| return to_zone_time | |
| end | |
| end |
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
| t = Time.at(1000000000) # => Sat Sep 08 21:46:40 EDT 2001 | |
| t.convert_zone("US/Pacific") # => Sat Sep 08 18:46:40 PDT 2001 | |
| time.convert_zone("US/Alaska") # => Sun Sep 08 17:46:40 AKDT 2001 | |
| t.convert_zone("UTC") # => Sun Sep 09 01:46:40 UTC 2001 | |
| t.convert_zone("Turkey") # = Sun Sep 09 04:46:40 EEST 2001 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment