Rails 3 时区配置问题
我在时区配置方面遇到了一些问题。
所以我看到了一些关于这个主题的帖子/问题,有些人说我应该在“application.rb”中添加以下配置。
config.time_zone = "Brasilia"
我已经这样做了,但即使在配置之后,如果在 Rails 控制台中运行以下代码,我会得到 (GMT+00:00) UTC
Time.zone
当 do
Time.now.in_time_zone
它在 GMT 0 响应
时也会发生同样的情况。我认为与此相关的另一个问题这是使用 datetime_select 标签选择日期时间时的情况。看起来它显示了正确的时间,但是当字段保存到数据库时也是在 UTC +00 上。
I've been having some problems with the configuration of timezone.
So I've seen some posts/questions about this topic and some say I should add the following configuration in the "application.rb".
config.time_zone = "Brasilia"
I've done that, but even after configuring this, if a run the following code in rails console I get (GMT+00:00) UTC
Time.zone
The same happens when a do
Time.now.in_time_zone
It responds in GMT 0.
Another problem that I think relates to this, is when choosing a datetime with the datetime_select tag. It seems as it's showing the right time but when the field is saved to the db is also on the UTC +00.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您检查过您的{environments}.rb 文件(例如environments/development.rb)吗? application.rb 中的配置值将被环境 .rb 文件中的相同值覆盖。也许您在development.rb 中设置了GMT?
当我将 config.time_zone = "Brasilia" 添加到development.rb 文件并运行
rails c
时,我得到:have you checked your {environments}.rb file (e.g. environments/development.rb)? The config values in application.rb are overridden by the same values in the environment .rb files. Perhaps you have GMT set in development.rb?
When I added
config.time_zone = "Brasilia"
to my development.rb file and ranrails c
, I get: