我将 environment.rb 中的 config.time_zone 设置为“UTC”,当我发出“select now();”时,我的 mySQL 服务器返回本地时区的当前时间 当我要求“选择 utc_timestamp;”时,在 utc 中
我正在运行 rails 2.1.2、mysql gem 2.7.3、activerecord gem 2.1.2,并且 mysql --version 返回“Ver 14.12 Distrib 5.0.27 for Win32 (ia32)”。
编辑:我的 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!
任何想法是什么原因造成的?