简体   繁体   中英

ruby error - invalid date

I have a date from DB in the following format - '1973-06-15' When I try to create a date object with

dob = DateTime.strptime(user.date_of_birth.to_s, "%Y-%m-%d")

I always get

invalid date

error. Outputting the date normally shows correct date. How to correctly parse dates in this case?

假设user.date_of_birth是一个DateTime(或Date)对象,则应该能够执行以下操作:

dob = user.date_of_birth.strftime("%Y-%m-%d")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM