我有这样的麻烦:当我创建对象并设置一些日期时间时,它正在 UTC TimeZone 中保存数据库。这是示例:
//showing full list of object properties
Grant _id: 5108ee29e6b564611400000, start_date: 2013-01-30 09:56:27 UTC
//then showing a.start_date
Wed, 30 Jan 2013 13:56:27 +0400
我试图禁止数据库使用 UTC。这是 mongoid.yml:
development:
options:
raise_not_found_error: false
sessions:
default:
use_activesupport_time_zone: true
use_utc: false
database: test_mongoid_production
hosts:
- localhost:27017
options:
consistency: :strong
在 application.rb 中:
config.time_zone = 'Moscow'
但它不起作用。
有人可以帮忙解决这个问题吗?
最佳答案
您可以更改应用程序的时区,以便 ruby 的日期对象自动配置日期。 MongoDB 将始终以 UTC 格式存储时间。
MongoDB 没有时区的内部知识。
关于ruby-on-rails - 是否可以使用 Rails 3 更改 MongoDB 中的默认时区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14601283/