environment.rb の config.time_zone を「UTC」に設定しており、「select now();」を発行すると、mySQL サーバーは現在の時刻をローカル タイム ゾーンで返します。「select utc_timestamp;」を要求すると、utc で
Rails 2.1.2、mysql gem 2.7.3、activerecord gem 2.1.2 を実行しています。mysql --version は、「Win32 (ia32) 用の Ver 14.12 Distrib 5.0.27」を返します。
編集: 私の environment.rb は UTC に設定されており、プロジェクトを開始して以来ずっとそうでした。サーバーを再起動しても、変更は反映されません。
record = Record.find(:first)
puts Time.now
# Tue Nov 25 17:40:48 -0800 2008
record.time_column = Time.now
record.save
mysql> select * from records;
---------------------
2008-11-26 01:40:48
#note that this is the same time, in UTC.
record = Record.find(:first)
puts record.time_column
Wed Nov 26 01:40:48 -0800 2008
#NOTE that this is eight hours in advance!
#All I've done is store a date in the database and retrieve it again!
これを引き起こす原因は何ですか?