I have a date as string as below
String test Date = "1/31/2020";
I am using the below code
public static String getPeriodMonth(String periodEndDate) {
LocalDate localDate;
YearMonth yearMonth = null;
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
localDate = LocalDate.parse(periodEndDate, formatter);
yearMonth = YearMonth.from(localDate);
}catch (Exception e) {
LOGGER.error("Error: "+ e.getMessage() + ">>" + e.getCause());
}
return yearMonth.toString();
}
I am getting the below Exception when excuting this code:
Error: Text '1/31/2020' could not be parsed at index 0>>null
Can someone help me what I am doing wrong here?