使用 Rails 4.0.0、ruby 2.0p247 和 mysql2 0.3.13 gem。MariaDB 5.5 中我的表中的一列
注意:mariadb 从 5.3 开始支持微秒精度
`updated_at` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
精度应该是微秒,所以我在我的模型文件中尝试过
before_save :set_update
def set_update
# also tried
# self.updated_at = "2013-10-03 12:35:00.123456 -700"
# self.updated_at = Time.now.strftime "%Y-%m-%d %H:%M:%S %6N"
# self.updated_at = Time.now.iso8601(6)
# doesn't work, still no microseconds
self.updated_at = Time.now.to_f
end
但在数据库中它仍然是
| updated_at |
+----------------------------+
| 2013-10-03 19:35:00.000000 |
+----------------------------+
为什么 rails/activerecord 不存储微秒?