新手问题 Rails sqlite3 时间显示

wwwicbd · 2016年01月15日 · 最后由 rei 回复于 2016年01月15日 · 1976 次阅读

新建一条

『实际时间为 北京时间 14 点左右』

2.3.0 :001 > ming = User.create(name:"小明",email:"[email protected]")
   (0.1ms)  begin transaction
  SQL (1.0ms)  INSERT INTO "users" ("name", "email", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["name", "小明"], ["email", "[email protected]"], ["created_at", "2016-01-15 06:04:44.095125"], ["updated_at", "2016-01-15 06:04:44.095125"]]
   (0.8ms)  commit transaction
 => #<User id: 3, name: "小明", email: "[email protected]", created_at: "2016-01-15 06:04:44", updated_at: "2016-01-15 06:04:44"> 

设置时区后再进入 console

# 时区
config.time_zone = "Beijing"
config.active_record.default_timezone = :local
2.3.0 :002 > exit
Cbd-MacBook-Pro:sample cbd$ rails c
Loading development environment (Rails 4.2.2)
2.3.0 :001 > gang = User.create(name:"小刚",email:"[email protected]")
   (0.2ms)  begin transaction
  SQL (0.3ms)  INSERT INTO "users" ("name", "email", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["name", "小刚"], ["email", "[email protected]"], ["created_at", "2016-01-15 14:05:47.858347"], ["updated_at", "2016-01-15 14:05:47.858347"]]
   (8.8ms)  commit transaction
 => #<User id: 4, name: "小刚", email: "[email protected]", created_at: "2016-01-15 06:05:47", updated_at: "2016-01-15 06:05:47"> 

疑问:DB 里的 created_at / updated_at 是不是只存一个时间的字面量而不是时间戳?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号