Skip to content

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

instance method

DateTime#iso8601

dt.iso8601([n=0]) → string

This method is equivalent to strftime(‘%FT%T%:z’). The optional argument n is the number of digits for fractional seconds.

Example
DateTime.parse('2001-02-03T04:05:06.123456789+07:00').iso8601(9)
                          #=> "2001-02-03T04:05:06.123456789+07:00"
See also .iso8601 #hour #jisx0301 #as_json also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0