DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); try { LocalDate date = formatter.parse(text, LocalDate::from); } catch (DateTimeParseException e) { // Thrown if text could not be parsed in the specified format }