Question

I'm using two JFormattedTextFields in Java for Date in my JFrame. I formatted them in format (DD/MM/YYYY).

How can i find difference between them in days?

Was it helpful?

Solution

You can use Joda Time

DateTime date1 = new DateTime(2013, 12, 20, 0, 0);
DateTime date2 = new DateTime(2013, 12, 23, 0, 0);
Days.daysBetween(date1, date2).getDays(); // Will return 3 
//since date2 is 3 days after date1

OTHER TIPS

Parse the dates, use Calendar standard class or Joda Time library to compare the dates.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top