Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Introduction

Joda-Time is a very popular Java library concerning date and time manipulation. It gives a much more intuitive and flexible API than that usually offered by the standard DateTime class.

In this tutorial, we’ll look at how to transform Joda-Time DateTime objects into standard Java Date ones and vice versa.

2. Setting Up Joda-Time

First, we should ensure that our project includes the joda-time library:

<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.12.6</version>
</dependency>

Alternatively, we can download the jar file and put it in our classpath.

3. Convert Joda-Time DateTime to Java Date

To convert a Joda-Time DateTime object to a standard Java Date we use the method called toDate(). Below is a simple example:

@Test
public void givenJodaDateTime_whenConvertingToJavaDate_thenConversionIsCorrect() {
    DateTime jodaDateTime = new DateTime();
    java.util.Date javaDate = jodaDateTime.toDate();
    assertEquals(jodaDateTime.getMillis(), javaDate.getTime());
}

In this test method, we create a new instance of DateTime from Joda-Time named jodaDateTime. Subsequently, we called the toDate() method on this Joda DateTime instance to obtain a corresponding java.util.Date object.

The test is performed using the assertEquals method, which asserts that the time in milliseconds retrieved from the original Joda DateTime object equals the time obtained from the new DateTime object created through the java.util.Date.

4. Convert Java Date to Joda-Time DateTime

It is also straightforward to convert a plain Java Date object into Joda-Time DateTime. We can use the DateTime constructor designed for java.util.Date parameter as follows:

@Test
public void givenJavaDate_whenConvertingToJodaDateTime_thenConversionIsCorrect() {
    java.util.Date javaDate = new java.util.Date();
    DateTime jodaDateTime = new DateTime(javaDate);
    assertEquals(javaDate.getTime(), jodaDateTime.getMillis());
}

Within the above test method, we actively instantiate a new java.util.Date object, representing the current date and time. Subsequently, we create a corresponding Joda DateTime object using the provided Java Date. The actual validation occurs using the assertEquals method, where we verify that the time in milliseconds is retrieved from the original java.util.Date object is equal to the time represented by the Joda DateTime object

5. Conclusion

In conclusion, one of the usual operations when working with dates and time in Java is converted between Joda-Time DateTime objects and standard Java Date.

Now that we have gone through the examples presented above, it should be easy for us to implement Joda-Time in our projects and easily convert these two types.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW