Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
active record timezone without rails

这次应该搞定了

Francis.J 2014-9-4 11:30:02

zone_default = Time.find_zone!("Asia/Shanghai")
Time.zone_default = zone_default

ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.default_timezone = :utc

Francis.J 2014-9-4 11:30:04 你看看

俞飞鹏 2014-9-4 11:30:23 好

Francis.J 2014-9-4 11:31:28 api 保存的时候 转成 utc 取出来的时候 再 time_zone 11:32:21 Francis.J 2014-9-4 11:32:21 这里 才是关键 xd

https://github.com/rails/rails/blob/d20270612cd9be3eed910171934a6b3463dbead7/activerecord/lib/active_record/timestamp.rb#L20

Francis.J 2014-9-4 11:33:22 我们 api 里面 默认不是 true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment