新手问题 Rails sqlite3 时间显示

wwwicbd · January 15, 2016 · Last by rei replied at January 15, 2016 · 1966 hits

新建一条

『实际时间为 北京时间 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 是不是只存一个时间的字面量而不是时间戳?

You need to Sign in before reply, if you don't have an account, please Sign up first.