convert String to DateTime

SkaveRat picture SkaveRat · Feb 4, 2010 · Viewed 153.1k times · Source

I need to parse following String into a DateTime Object:
30/Nov/2009:16:29:30 +0100

Is there an easy way to do this?

PS: I want to convert the string above as is. The colon after the year is not a typo. I also want to solve the problem with Ruby and not RoR.

Answer

Kaleb Brasee picture Kaleb Brasee · Feb 4, 2010

DateTime.strptime allows you to specify the format and convert a String to a DateTime.