Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 Rails:本地和生产上的时区差异_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 4 Rails:本地和生产上的时区差异

Ruby on rails 4 Rails:本地和生产上的时区差异,ruby-on-rails-4,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-2

我有一个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)'
我应该怎么做才能使其在本地和生产上保持一致

检查这个,看起来你正在做一些“不要”部分的工作:

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)

要避免时区问题,只需使用:

Date.current     # => Mon, 01 Feb 2016
DateTime.current # => Mon, 01 Feb 2016 17:32:18 +0000
Time.current     # => Mon, 01 Feb 2016 17:33:17 UTC +00:00

您正在使用
时区。现在
?我将数据时间作为字符串并将其作为参数传递以保存记录您已设置
配置活动\u记录。默认\u时区
?不,我尚未设置this@kalelc它应该是什么?我没有使用任何这些,只是花时间和节省时间。我没有做任何这些