4
我使用Mongoid适配器观察到的行为是将当前系统时区的'时间'字段保存到数据库中。请注意,这是系统时间,而不是Rail的环境的Time.zone。如果我更改系统时区,则随后的保存会提取当前的系统时区。如何使用Mongoid在Mongo中存储UTC时间值?
# system currently at UTC -7
@record.time_attribute = Time.now.utc
@record.save
# in mongo, the value is "time_attribute" : "Mon May 17 2010 12:00:00 GMT-0700 (QYZST)"
@record.reload.time_attribute.utc? # false
你定义哪些字段time_attributes? – shingara 2010-05-25 18:34:13
是否有任何理由可以将操作系统日期设置为UTC? – 2010-06-18 12:13:48