Converting a date string to a DateTime object using Joda Time library
DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss").parseDateTime("04/02/2011 20:27:05");
I know this is an old question, but I wanted to add that, as of JodaTime 2.0, you can do this with a one-liner:
DateTime date = DateTime.parse("04/02/2011 20:27:05",
DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss"));
Use DateTimeFormat
:
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss");
DateTime dt = formatter.parseDateTime(string);