我正在通过我的ActiveRecord将一些字符串(看起来像日期)插入到sqlite3数据库中,数据库正在修改字段,使其看起来像日期。例如:
"4-2" => "2-Apr" #Not only a date but the order has been reversed.
"6-7-12" => "7/12/2006" #Again not only a date but the order has been changed.我寻找了一个可以防止这种情况发生的ruby字符串函数,但没有找到任何东西。
有没有其他人遇到过这样的事情,你知道有什么变通方法或修复方法吗?
发布于 2012-02-21 21:47:14
如果可以预测字符串的格式,请在保存字符串之前使用以下代码将其分析为date对象。
Date.strptime '6-7-12', '%m-%d-%y'
=> Thu, 07 Jun 2012https://stackoverflow.com/questions/9377832
复制相似问题