0

I have a String with DD/MM/YYYY date format, and I want to check if the new date is older than today. I use LocalDate.now(); However, i have an exception when I run this code:

LocalDate today = LocalDate.now();
DateTimeFormatter FORMATO_DIA = DateTimeFormatter.ofPattern("dd/mm/yyyy");

String otherDay = "02/12/1995";
LocalDate otherDay2 = LocalDate.parse(otherDay, FORMATO_DIA);
if (today.isBefore(otherDay2)){
    System.out.println("NICE");
}

Exception text:

Exception in thread "main" java.time.format.DateTimeParseException: Text '02/12/1995' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {DayOfMonth=2, Year=1995, MinuteOfHour=12},ISO of type java.time.format.Parsed

Ayrton
  • 2,218
  • 1
  • 14
  • 25
ras212
  • 67
  • 1
  • 5

1 Answers1

3

It's because you are using mm, which stands for minutes. You must use MM for month

Ayrton
  • 2,218
  • 1
  • 14
  • 25