【发布时间】:2014-08-13 20:38:16
【问题描述】:
我需要关闭 Rails 应用程序和 Mysql 之间的时间转换。
ActiveRecord source 的这条评论说:
# Timestamps are in UTC by default but you can use the local timezone by setting:
#
# config.active_record.default_timezone = :local
但是,我的服务器使用UTC 时区,如果使用:local 或:utc 选项,它不会有任何区别。所需的时区是'Brasilia'。
生产服务器上的 Rails 控制台显示转换:
$ RAILS_ENV=production bundle exec rails c
Loading production environment (Rails 4.1.4)
2.0.0 :001 > Time.current
=> Wed, 13 Aug 2014 17:34:15 BRT -03:00
2.0.0 :002 > Schedule.where(startDateTimeSchedule: Time.current)
Schedule Load (1.0ms) SELECT `Schedule`.* FROM `Schedule` WHERE `Schedule`.`startDateTimeSchedule` = '2014-08-13 20:34:25'
P.S.:关于这个主题的高投票问题的accepted answer 是错误的。
【问题讨论】:
标签: mysql ruby-on-rails activerecord ruby-on-rails-4 timezone