2

I have a piece of code here to calculate someone's age with the SQL date type in java. The code works fine, but however you can't see it in the code pasted here, but in my netbeans environment the get methods are crossed out, but only in this line:

LocalDate datumDB = LocalDate.of(gbdat.getYear() + 1900, gbdat.getMonth() + 1, 
  gbdat.getDate());

someone any idea why?

this line isn't crossed out:

int leeftijd = datumVanVandaag.getYear() - datumDB.getYear();

this is my code:

private void checkSpelerGeschiktVoorPloeg(Persoon p) {       

    Date gbdat = p.getGbDatum();

    LocalDate datumVanVandaag = LocalDate.now();

    LocalDate datumDB = LocalDate.of(gbdat.getYear() + 1900, gbdat.getMonth() + 1, gbdat.getDate());

    int leeftijd = datumVanVandaag.getYear() - datumDB.getYear();       

}
Wouter
  • 3,976
  • 2
  • 31
  • 50

1 Answers1

7

The strikeout indicates that those methods are deprecated. You should use either java.util.Calendar or the new Java 8 Datetime API (which is the new-and-improved API that the LocalDate you're using is part of) to calculate these values for a date.

For instance the API document says:

@Deprecated
public int getYear()

Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.YEAR) - 1900.
Returns a value that is the result of subtracting 1900 from the year that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

Community
  • 1
  • 1
Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
  • And to add to that, `LocalDate.getDate()` et al are _not_ deprecated, which is why they're not crossed out. – yshavit Jan 06 '16 at 18:26