0

The dateutil library from Python is super useful for parsing strings of various common formats into datetime objects. Is there something similar for Ruby?

Dasmowenator
  • 5,505
  • 5
  • 36
  • 50

1 Answers1

1

Date#parse and Date#strptime are in the ruby standard library. You need to require 'date' first.

I have also used the chronic gem when those were insufficient.

Tom
  • 412
  • 2
  • 9
  • A static code analyzer like rubocop will tell you not to use DateTime and favor Date or Time if one of the simpler classes will do. Unless a DateTime method is being called with a start argument such as Date::ENGLAND, Date::GREGORIAN, Date::ITALY or Date::JULIAN, it will be less performant. TLDR: You can almost always use Time instead of DateTime. – Tom Nov 03 '17 at 19:31