我將environment.rb中的config.time_zone設置爲「UTC」,當我發出「select now(); mySQL服務器返回當地時區的當前時間」並在utc中請求「select utc_timestamp;」Ruby on Rails:當我給DB寫入時間時,爲什麼我的時間區域會變得冗長,然後再讀回來?
我正在運行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!
任何想法是什麼原因造成的?