简体   繁体   English

MySQL-为Rails应用程序设置默认时区

[英]MySQL - setting default timezone for a Rails application

I am using this setup in config/environments/production.rb : 我在config/environments/production.rb使用此设置:

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

But when I am deploying the application to the server, I am seeing these warning messages: 但是,当我将应用程序部署到服务器时,我看到以下警告消息:

warning: :database_timezone option must be :utc or :local - defaulting to :local

How to fix this warning? 如何解决此警告? Should I add another config.active_record.default_timezone with :utc ? 我应该用:utc添加另一个config.active_record.default_timezone吗?

Rails cannot use the timezone I set above? Rails无法使用我在上面设置的时区?

Thank you. 谢谢。

From: http://guides.rubyonrails.org/configuring.html#configuring-active-record 来自: http : //guides.rubyonrails.org/configuring.html#configuring-active-record

config.time_zone sets the default time zone for the application and enables time zone awareness for Active Record. config.time_zone设置应用程序的默认时区,并为Active Record启用时区识别。

config.active_record.default_timezone determines whether to use Time.local (if set to :local) or Time.utc (if set to :utc) when pulling dates and times from the database. config.active_record.default_timezone确定从数据库中提取日期和时间时是使用Time.local(如果设置为:local)还是Time.utc(如果设置为:utc)。 The default is :local. 默认是:local。

So based on this, if you want to override your default timezone to Eastern time, you'd want to do: 因此,基于此,如果您想将默认时区替代为东部时间,则需要执行以下操作:

config.time_zone = 'Eastern Time (US & Canada)'
config.active_record.default_timezone = :local

Let me know if this helps! 让我知道这是否有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM