- RubyとRailsにおけるTime, Date, DateTime, TimeWithZoneの違い
- Railsと周辺のTimeZone設定を整理する (active_record.default_timezoneの罠)
を参考に
- 素のRubyならTimeクラスを使う。
- RailsならTimeWithZoneクラスを使う。
# currentはapplication.rbのタイムゾーンを使う。戻り値もTimeWithZone。
l Time.current
=> 2014/12/31 10:00:00, EST, ActiveSupport::TimeWithZone
# zone.nowはcurrentと同じ。
l Time.zone.now
=> 2014/12/31 10:00:00, EST, ActiveSupport::TimeWithZone
よりTime.zone.nowを使えばapplication.rbの設定を使ってくれそう
とあるがリファレンスたどって要調査
現在の設定は
* config.time_zone = 'Tokyo'
* config.active_record.default_timezone = 'local' (DBのtimezoneに合わせる)
* DBはJST(Asia/Tokyo)
ってそもそもJSTに寄せようとしているが良いのか。って所も要調査だが。