我有一个带有日期时间字段的表单
.form-group
= f.label :sale_date, class: "col-sm-2 control-label"
.col-sm-10
= f.date_select :sale_date, class: "form-control", required: true
当我在表单上选择任何日期并在控制台中提交时,我发现它实际上提交了昨天的日期,例如,如果我选择了今天的日期,那么我会看到
"sale"=>{"amount"=>"400", "new_sale"=>"0", "sale_date(1i)"=>"2015", "sale_date(2i)"=>"7", "sale_date(3i)"=>"31", "employee_id"=>"2"}, "commit"=>"Create Sale"}
(0.2ms) SELECT "employees".* FROM "employees" WHERE "employees"."id" = $1 LIMIT 1 [["id", 2]]
SQL (0.5ms) INSERT INTO "sales" ("amount", "employee_id", "sale_date", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["amount", 400], ["employee_id", 2], ["sale_date", "2015-07-30 23:00:00.000000"], ["created_at", "2015-07-31 10:23:58.551966"], ["updated_at", "2015-07-31 10:23:58.551966"]]
今天将31/07/2015
转换为"2015-07-30 23:00:00.000000"
我不知道发生了什么......