Java – Calculate Difference Between Two Dates Using Joda Time

Take a look @ Joda-Time FAQ

You can use a PeriodFormatter to get the format of your choice.

Try the following sample code.

DateTime dt = new DateTime();

DateTime twoHoursLater = dt.plusHours(2).plusMinutes(10).plusSeconds(5);

Period period = new Period(dt, twoHoursLater);

PeriodFormatter HHMMSSFormater = new PeriodFormatterBuilder()
        .toFormatter(); // produce thread-safe formatter


Java JSP – JSTL Date Format Example

This example show how to format date in JSP using format tag library.

<%@ taglib uri="" prefix="fmt" %>

    <jsp:useBean id="date" class="java.util.Date"/>
    Today is: <fmt:formatDate value="${date}" type="date" pattern="dd-MMM-yyyy"/>


Java – Convert java.util.Date to JodaTime

java.util.Date date = new java.util.Date();

org.joda.time.DateTime dateTime = new org.joda.time.DateTime(date);

Make sure date isn’t null, though, otherwise it acts like new new DateTime()

Page 1 of 212