Using Joda time

Joda time is a popular open source library that provides replacement for the standard Java date and time classes like Date, Calendar and SimpleDateFormat.

Joda time is a popular open source library that provides replacement for the standard Java date and time classes like Date, Calendar and SimpleDateFormat. Lot's of projects use Joda time instead JDK date and time.

Joda time is interoperable with JDK date and time.

First add Joda time JARs to build path.

To get current date create instance of DateTime class:

DateTime currentDate = new DateTime();

 

To get current day, month, year etc. call getDayOfMonth(), getMonthOfYear(), getYear() etc.

To add or subtract call plusXXX() or minusXXX() method.

To format or parse date use class DateTimeFormatter.

All of this is much easier than using standard JDK date and time.