I am trying to find out someones age. I am following the answer given in here: How do I calculate someone's age in Java?
This is what I have so far:
public void setDOB(String day, String month, String year){
LocalDate birthDate = new LocalDate(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));
}
I am getting a an error when declaring the birthDate variable. I am getting the following error:
LocalDate(int,int,int) has private access in LocalDate
. I don't know what this error means but I am assuming its to do with data access (e.g. private, public, etc)
LocalDate is an immutable date-time object that represents a date, often viewed as year-month-day. Other date fields, such as day-of-year, day-of-week and week-of-year, can also be accessed.
It should not be null. Return value: This method returns LocalTime which is the parsed local date-time. Exception: This method throws DateTimeParseException if the text cannot be parsed.
LocalDate is an immutable class that represents Date with default format of yyyy-MM-dd. We can use now() method to get the current date.
The constructor you are calling is private.
You need to call
LocalDate birthDate = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));
to construct your date.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With