开发者

Ruby: Convert BST time to UTC

开发者 https://www.devze.com 2023-01-28 14:18 出处:网络
script/console >> t = Time.at(1158609371) => Mon Sep 18 20:56:11 +0100 2006 >> t.zone => \"BST\"
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

How come it changed from Sep 18 2006 to Jan 01 2000? Timezone is setup to use "UTC" in environment.rb. And just so you are aware I have tried numerous variations of line开发者_如何转开发 s.creation_tsz = t.utc . All with failure.


Is it possible that in the database, s.creation_tsz stores only a time, but not a date part, for example a MySQL TIME type, as opposed to the TIMESTAMP or DATETIME type.

0

精彩评论

暂无评论...
验证码 换一张
取 消