Difference between two date strings in java
<p>I am trying to calculate difference between two date strings both of which are taken from user through a html form in format (yyyy/MM/dd)
Code:</p>

<pre><code>public boolean diffDate() throws ParseException
 {
     date1 = getissuedate();
     date2 = getduedate();
         Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy/MM/dd");
    SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy/MM/dd"); 
Date date_old = formatter1.parse(date1);
Date date_new = formatter2.parse(date2);
long milis1 = date_old.getTime();
long milis2 = date_new.getTime();

long diff = milis2 - milis1;       

    if( diff&lt;3 || diff&gt;3)
    {
        return true;
    }
    else 
    {       
        return false;
    }       
 }
</code></pre>

<p>Now am using an if condition to report error in my webpage if difference between the date is not equal to 3.
Code:</p>

<pre><code>try {
        if(diffDate())
        {
            errors.add("duedate", new ActionMessage("error.duedate.required"));
        }
    } catch (ParseException ex) {
        Logger.getLogger(IssueBookForm.class.getName()).log(Level.SEVERE, null, ex);
    }
</code></pre>

<p>where error.duedate.required is mapped to "check date"   </p>

<p>So, the issue is "check date" error is printed for any value of both date string.</p>
