0
    Date date1 = null,date2=null;
    SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

    try {
        date1= format.parse(jLabel2.getText());
    } catch (ParseException ex) {
        Logger.getLogger(Settlements.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        date2= format.parse(jLabel3.getText());
    } catch (ParseException ex) {
        Logger.getLogger(Settlements.class.getName()).log(Level.SEVERE, null, ex);
    }
long subDateValue = date2.getTime()-date1.getTime();
long subValueinDays = subDateValue/(24 * 60 * 60 * 1000);
System.out.println(subValueinDays + "Days");

// I got an Exception:java.text.ParseException: Unparseable date: "10/10/2014" jLabel1=10/10/2014 jlabel2=11/10/2014

  • possible duplicate of [How to parse a date?](http://stackoverflow.com/questions/999172/how-to-parse-a-date) – Basil Bourque Sep 27 '14 at 17:17
  • Possible duplicate of this [previous question](http://stackoverflow.com/q/26064109/230513). Have you tried `LocalDate` and `Period`? – trashgod Sep 27 '14 at 17:52

1 Answers1

1

Exception:java.text.ParseException: is because the format you specified in the SimpleDateFormat() is different from the String format of the Date you are parsing.

When you specify this SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); it expects that the String format of your date will be something like this for example 01/01/2014 11:23:45

Use this one

SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH);
SparkOn
  • 8,806
  • 4
  • 29
  • 34
  • You have to accept the answer if it resolved your problem. It may be helpful for someone else. – Naili Sep 27 '14 at 15:16