Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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()
        .printZeroAlways()
        .minimumPrintedDigits(2)
        .appendHours().appendSeparator("-")
        .appendMinutes().appendSeparator("-")
        .appendSeconds();
        .toFormatter(); // produce thread-safe formatter

System.out.println(HHMMSSFormater.print(period));


This post first appeared on Javac, please read the originial post: here

Share the post

Java – Calculate Difference Between Two Dates Using Joda Time

×

Subscribe to Javac

Get updates delivered right to your inbox!

Thank you for your subscription

×