新手问题 time_select 显示 time_zone 问题

luffycn · May 01, 2015 · Last by marksloan replied at May 04, 2015 · 2147 hits

目的是做到这样的效果

  1. time_select 表单显示的是 application.rb 中指定的 timezone 时间,form_for 中的 edit, new 都显示成相应的 localtime
  2. 同时保存在数据库用的是 utc 时间

有什么办法嘛?

第一个没明白你的意思,好绕,说实际场景,为何要那么做

第二个:MySQL 用 TIMESTAMP 作为日期字段的类型, TIMESTAMP 保存的时候,MySQL 会转换成 UTC 来存储:

MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. (This does not occur for other types such as DATETIME.)

数据库存 UTC,显示用 local time 不正是最好的方案吗?

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