Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Date.iso8601

Date.iso8601(string='-4712-01-01'[, start=Date::ITALY], limit: 128) → date

Creates a new Date object by parsing from a string according to some typical ISO 8601 formats.

Example
Date.iso8601('2001-02-03')        #=> #<Date: 2001-02-03 ...>
Date.iso8601('20010203')          #=> #<Date: 2001-02-03 ...>
Date.iso8601('2001-W05-6')        #=> #<Date: 2001-02-03 ...>

Raise an ArgumentError when the string length is longer than limit. You can stop this check by passing ‘limit: nil`, but note that it may take a long time to parse.

See also #iso8601 ._iso8601 .jd .httpdate also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0