Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
Created September 4, 2014 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhjguxin/e6386e720e266dcba964 to your computer and use it in GitHub Desktop.
Save jhjguxin/e6386e720e266dcba964 to your computer and use it in GitHub Desktop.
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