This tutorial shows how we can use joda date time API.

Java’s standard date and time classes (mainly java.util.Date and java.util.Calendar) have limited functionality and have a number of design problems. The fact that many of constructors and methods of java.util.Date are deprecated.

Joda Time has a better thought out API than what is available in Java’s date and time standard library. There are classes for timestamps with or without a timezone, classes for holding only a date (year, month, day) or only a time of day, classes for periods, durations and intervals, it supports the ISO 8601 format (which is the standard format in XML documents) and much more.

Now JDK 8 is out and it has a new date and time API which is similar to Joda Time. For more information please read package java.time.

JDK 1.6 or later
Eclipse 3.2 or later
Maven 2 or later
Joda Date Time API

Now we will see how we can make this happen step by step

Step 1. Create a standalone maven project in Eclipse

Go to File -> New -> Other. On popup window under Maven select Maven Project. Then click on Next. Select the workspace location – either default or browse the location. Click on Next. Now in next window select the row as highlighted from the below list of archtypes and click on Next button.


Now enter the required fields (Group Id, Artifact Id) as shown below

Group Id : com.roytuts
Artifact Id : joda-date-time

Step 2. Add joda-time dependency to the pom.xml file.

<!-- joda date time -->

Step 3. Write a class which will show how to use joda date time

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class JodaDateTimeTest {

   * @param args
  public static void main(String[] args) {
    DateTime dateTime = new DateTime(DateTimeZone.forOffsetMillis(0));

    LocalDateTime date =;
    DateTimeZone tz = DateTimeZone.getDefault();
    DateTime dateTime2 = date.toDateTime(tz);

    DateTime dateTimeCustom = new DateTime("2015-05-15T12:58:50");
    System.out.println(new Date(dateTimeCustom.getMillis()));

    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd hh:mm:ss");
    String dt = dateTime.toString(fmt);


Step 4. Now run the above class and see the output in the console.

2015-06-10 07:03:47

That’s all. Thank you for reading.

I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on Roy Tutorials Twitter Facebook  Google Plus Linkedin Or Email Me

Leave a Reply

Your email address will not be published. Required fields are marked *