script/console
>> t = Time.at(1158609371)
=> Mon Sep 18 20:56:11 +0100 2006
>> t.zone
=> "BST"
>> s = Shop.find(:first)
>> s.creation_tsz = t.utc
=> Mon Sep 18 19:56:11 UTC 2006
>> s.creation_tsz.zone
=> "UTC"
>> s.save
>> s = Shop.find(:first)
>> s.creation_tsz
=> Sat Jan 01 19:56:11 UTC 2000怎么会从2006年9月18日变成2000年1月1日呢?时区设置为在environment.rb中使用"UTC“。正如你所知,我已经尝试了s.creation_tsz = t.utc行的许多变体。一切都以失败告终。
发布于 2010-12-04 01:58:27
有没有可能在数据库中,s.creation_tsz只存储时间,而不存储日期部分,例如MySQL TIME type,而不是TIMESTAMP or DATETIME type。
https://stackoverflow.com/questions/4348311
复制相似问题