ruby-on-rails-4 - 导轨 : Timezone difference on local and production

标签 ruby-on-rails-4

我有一个 Sidekiq 工作程序,从远程 Oracle 数据库获取记录并将其保存在 postgres 数据库中。大多数数据由日期和时间字段组成。我在生产中遇到的问题是,它保存了不同时区的数据时间,相差 5 小时。虽然它在本地运行良好。这是一个例子:

From Oracle DB => 2016-01-27 07:59:29 +0500

Saved on local => 2016-01-27 07:59:29 -0500

On Production  => 2016-01-27 02:59:29 -0500

在 config/application.rb 中我设置了:

config.time_zone = 'Eastern Time (US & Canada)'

我应该怎样做才能使其在本地和生产上保持一致?

最佳答案

检查这个http://www.elabs.se/blog/36-working-with-time-zones-in-ruby-on-rails ,看起来你正在做一些不该做的事情:

Time.now # Returns system time and ignores your configured time zone. (2015-08-27 14:09:36 +0200)
Time.parse("2015-08-27T12:09:36Z") # Will assume time string given is in the system's time zone. (2015-08-27 12:09:36 UTC)
Time.strptime("2015-08-27T12:09:36Z", "%Y-%m-%dT%H:%M:%S%z") # Same problem as with Time.parse. (2015-08-27 12:09:36 UTC)
Date.today # This could be yesterday or tomorrow depending on the machine's time zone, see https://github.com/ramhoj/time-zone-article/issues/1 for more info. (Thu, 27 Aug 2015)

关于ruby-on-rails-4 - 导轨 : Timezone difference on local and production,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35133302/

相关文章:

ruby-on-rails - Geokit ActiveModel::MissingAttributeError: 无法写入未知属性 `within`

javascript - 在我的 View 页面中实现两个选择

ruby-on-rails - 为 Rails 4 禁用 ActiveRecord

ruby-on-rails-4 - 在Rails中使用Devise时是否需要 “Users” Controller

ruby-on-rails - 如何在连接模型中按列对关联模型进行排序(:through)

ruby-on-rails - 不同的模型如何在 Rails 中使用相同的登录页面

javascript - rails 4 : coffeescript only works when there is a post request or when i reload the page

css - Bootstrap - 导航栏折叠菜单不显示

ruby-on-rails - 在 rails 中添加逗号分隔列表的链接

ruby-on-rails - 在使用 paranoia (acts_as_paranoid) 恢复记录后更​​新计数器缓存列