新手问题 time_select 显示 time_zone 问题

luffycn · 2015年05月01日 · 最后由 marksloan 回复于 2015年05月04日 · 2143 次阅读

目的是做到这样的效果

  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 不正是最好的方案吗?

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