Domanda

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?

È stato utile?

Soluzione

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

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top