In this Java tutorial we will learn
how to parse String to Date using Joda-Time library, for example, we will convert date String
"04-12-2014" to
java.util.Date object which represent this date. Before Java 8 introduced its
new Date and Time API, Joda was only reliable, safe and easy way to deal with date and time intricacies in Java. Java's own Date and Time was not that great, starting from JDK 1.1 when they made java.util.Date a mutable object and when they introduced
Calendar in Java 1.2. It is one of the most criticized feature of Java on communities along with
checked exception and
object cloning. Even though Java 8 has corrected its mistake with an excellent, shiny new API, which address all past issue, Joda date and time library still has a role to play in Java systems. First and foremost reason is because most of the large banks and clients are still running on Java 1.6 and will likely take another 5 to 6 year to adopt Java 8, Joda is the only friend you can trust to deal with date and time nightmares. One of the most common task in Java is to parse String to Dates and even though Java provides a utility class called
SimpleDateFormat, its not safe to use in multi-threaded environment until you know
how to use thread confinement to make SimpleDateFormat thread-safe. Many beginners either create new instance of SimpleDateFormat each time they have to convert String to Date or commit classical mistake of storing it in an instance or static variable, only to face mysterious issues later. Since most of the Joda Time classes are Immutable, you can use them easily and safely in concurrent application.