title: Difference of Dates in Java in Years
body: <pre><code>Date currentDate=new Date();
  DateFormat formatter=new SimpleDateFormat("dd-MM-yyyy");; 
  Date date =(Date)formatter.parse(birthDate);     //birthDate is a String, in format dd-MM-yyyy
  long diff = currentDate.getTime() - date.getTime();
  long d=(1000*60*60*24*365);
  long years = Math.round(diff / d);
  age=(int) years;
  </code></pre>
  
  <p>The value of age is not returning right. What am I doing wrong?</p>
  
  <pre><code>Enter your birthdate: (in format dd-MM-yyyy)
  25-07-1992
  Current Date: Tue Apr 21 14:05:19 IST 2015
  Birthday: Sat Jul 25 00:00:00 IST 1992
  
  Output: Age is: 487
  </code></pre>