LoginSignup
1
0

More than 5 years have passed since last update.

Time#getlocal と Time#localtime の違い

Posted at

結論

  • Time#getlocal は、Time オブジェクトを新しく生成して返す、非破壊的メソッド。
  • Time#localtime は、元の Time オブジェクトを変更する、破壊的メソッド。

検証

  • Ruby 2.3.1
[1] pry(main)> require 'time'
=> true
[2] pry(main)> Time.now.zone
=> "JST"
[3] pry(main)> t = Time.parse("Wed Aug 27 13:08:45 +0000 2008")
=> 2008-08-27 13:08:45 +0000
[4] pry(main)> t.getlocal
=> 2008-08-27 22:08:45 +0900  # Time#getlocal
[5] pry(main)> t.zone
=> nil                        # tはUTCのまま
[6] pry(main)> t.localtime
=> 2008-08-27 22:08:45 +0900  # Time#localtime
[7] pry(main)> t.zone
=> "JST"                      # tはJSTに変わっている

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0