title: How do I calculate someone's age in Java?
body: <p>I want to return an age in years as an int in a Java method.
  What I have now is the following where getBirthDate() returns a Date object (with the birth date ;-)):</p>
  
  <pre><code>public int getAge() {
      long ageInMillis = new Date().getTime() - getBirthDate().getTime();
  
      Date age = new Date(ageInMillis);
  
      return age.getYear();
  }
  </code></pre>
  
  <p>But since getYear() is deprecated I'm wondering if there is a better way to do this? I'm not even sure this works correctly, since I have no unit tests in place (yet).</p>