Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
これが私のIRBセッションです
1.9.2p290 :020 > Date.strptime("31-2-2010", "%d-%m-%Y") ArgumentError: invalid date
適切な値を指定しましたが、が返されArgumentErrorます。ここで何かが足りませんか?
ArgumentError
はい、何かが足り ません。年に関係なく、2月には31日はありません。
無効な日付を指定しました。
Time.strptime("31-2-2010", "%d-%m-%Y")それはあなたに与えることに注意してください2010-03-03 00:00:00 +0000。
Time.strptime("31-2-2010", "%d-%m-%Y")
2010-03-03 00:00:00 +0000
私はTime.strptime("31-2-2010", "%d-%m-%Y").to_date無効な日付エラーを避けるために使用します。
Time.strptime("31-2-2010", "%d-%m-%Y").to_date