10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsでは Date#to_time よりも Date#in_time_zone を使いましょう

Posted at

TimeクラスよりもTimeWithZoneの方がタイムゾーンの扱いが上手いらしいのでそちらを使いましょう。

.rb
Date.new(2017,2,3).to_time
2017-02-03 00:00:00 +0900 # Time クラス
Date.new(2017,2,3).in_time_zone
Fri, 03 Feb 2017 00:00:00 JST +09:00 # TimeWithZone クラス

実際にto_timeが原因で困ったことになったことはないんですが、Railsプロジェクト内で使うクラスは統一してたほうがスッキリするので私はこちらを使っています。

参考

10
9
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
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?