0

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?

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
Rahul Sharma
  • 63
  • 3
  • 13

2 Answers2

2

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
Pshemo
  • 122,468
  • 25
  • 185
  • 269
  • 1
    Cool, he just improved his copy paste skills. Also, he wants to parse some dates, so your answer is incomplete. – Silviu Burcea Oct 20 '13 at 13:50
  • @SilviuBurcea I knot that this answer is not full, it is intentional. OP will have to do his portion of work by reading docs or tutorials to convert Date to DateTime (which is not hard). – Pshemo Oct 20 '13 at 13:56
0

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

Silviu Burcea
  • 5,103
  • 1
  • 29
  • 43