【问题标题】:Ruby: Convert BST time to UTCRuby:将 BST 时间转换为 UTC
【发布时间】:2011-05-19 21:33:14
【问题描述】:
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 的变体。都以失败告终。

【问题讨论】:

    标签: ruby-on-rails ruby datetime activerecord time


    【解决方案1】:

    是否有可能在数据库中,s.creation_tsz 仅存储时间,而不存储日期部分,例如 MySQL TIME type,而不是 TIMESTAMP or DATETIME type

    【讨论】:

    • 将数据类型从时间更改为日期时间。固定的。谢谢
    猜你喜欢
    • 2021-09-05
    • 2018-09-17
    • 1970-01-01
    • 2012-07-07
    • 2011-05-02
    • 2020-12-14
    • 2015-03-01
    • 2013-02-03
    • 1970-01-01
    相关资源
    最近更新 更多