This post will discuss how to convert a date string to a Joda Time DateTime object in Java.

Before the introduction of to java.time package with Java 8, the standard date and time classes are very poor. The Joda-Time library provides a quality replacement for the date and time classes for Java.

To parse a date-time from the given text into a new DateTime object, you can simply use the DateTimeFormatter.parseDateTime() method. To create a formatter from a pattern string, you can call the static factory method DateTimeFormat.forPattern().

Download Code

Output (will vary):

2017-12-24T14:17:21.000-10:30

 
To use a specified time zone for parsing, use the withZone(DateTimeZone) method.

Download Code

Output (will vary):

2017-12-22T14:17:21.000Z

That’s all about converting a date string to a Joda Time DateTime object in Java.