Ruby 1.87 vs 1.92 Date.parse

前端 未结 5 2005
甜味超标
甜味超标 2021-02-01 12:56

In Ruby 1.87 I could do:

Date.parse (\"3/21/2011\")

Now in 1.9.2 I get:

ArgumentError: invalid date

<
5条回答
  •  粉色の甜心
    2021-02-01 13:50

    Use strptime and give a specific time format.

    ruby-1.9.2-p136 :022 > Date.strptime '03/21/2011', '%m/%d/%Y'
     => #
    

    See michaelmichael's response for the reason for this difference between Ruby versions.

提交回复
热议问题