2009-06-22 58 views
0

我已經設置在environment.rbconfig.time_zone = 'UTC',而我仍然得到了一些怪異的行爲Rails的內置日期時間字段:怪異created_at行爲

>> Time.now 
=> Sun Jun 21 17:05:59 -0700 2009 
>> Feedback.create(:body => "testing") 
=> #<Feedback id: 23, body: "testing", email_address: nil, name: nil, created_at: "2009-06-22 00:06:09", updated_at: "2009-06-22 00:06:09"> 
>> Time.parse(Feedback.last.created_at.to_s) 
=> Mon Jun 22 00:06:09 UTC 2009 

有什麼想法?

回答

3

它看起來像是在ActiveRecord對象中正確設置時區,所以我不認爲你需要擔心太多。如果您想強制Rails中的時間戳使用UTC,則可以使用Time.utc

Time.now.utc 
=> Mon Jun 22 00:54:21 UTC 2009