First of all, it's not good to use year as two digits as a string, Why?
Explanation
to parse your date, it is easy, you can use:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MMM-yy")
.withLocale(Locale.US);
LocalDate ld = LocalDate.parse("15-May-84", formatter);
But
This will return 2084-05-15
, which I think you are not looking to this, but you look to 1984-05-15
.
Quick Fix
So to solve this, you can use use minusYears(100)
:
LocalDate ld = LocalDate.parse("15-May-84", formatter).minusYears(100);
But
Which can be a problem to other years like 15-May-20
which will return 1920-05-15
.
For that I don't advice at all to use two digits in your year as a
string.
Unless
unless you have another confirmation that your date is between 1900
and 1999
, or between 2000
and 2999
. in this case you can create a (safe) custom parser!
Important
Don't use the legacy Date library, instead use only the modern java.time
API