首页 > 技术文章 > 同时可以修改时间和日期的datetime_select and 有关时间的转换

iwangzheng 2015-08-10 17:03 原文

 <%= f.datetime_select :updated_at %> 可以保存时间和日期

 

存一个8月5号,总会自动保存成5月8,于是做了限制

s = "08/20/2015 3:31 PM"
dt = DateTime.strptime s, "%m/%d/%Y %H:%M %p"

参考文档:http://ruby-doc.org/stdlib-2.2.2/libdoc/date/rdoc /Date.html#method-c-strptime
http://ruby-doc.org/stdlib-2.2.2/libdoc/date/rdoc/Date.html#method-i-strftime

推荐阅读