【问题标题】:Rails, how to store a birthday string "06/20/1980" in a timestamp field in the db?Rails,如何在数据库的时间戳字段中存储生日字符串“06/20/1980”?
【发布时间】:2011-12-17 01:24:08
【问题描述】:

我收到了来自 FB 的生日祝福,字符串形式如下:06/20/1980

我想将其保存在我的数据库 User.birthday 中,这是一个时间戳。但它失败了。

如何保存?谢谢

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-3 postgresql


【解决方案1】:

Rubys Date 类可以解析任意格式。

Date.strptime("06/20/1980", "%m/%d/%Y")

【讨论】:

  • 那是返回无效日期
  • @AnApprentice:我发现这不太可能,除非您忘记在 Date.strptime 调用中包含格式字符串。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-27
  • 2012-12-17
  • 1970-01-01
  • 2013-05-03
相关资源
最近更新 更多