LocalDate format() method in Java
The format() method of LocalDate class in Java method formats this date using the specified formatter.
public String format(DateTimeFormatter formatter)
Parameter: This method accepts a parameter obj which specifies the formatter to be used and it is not null.
Exceptions: The function throws only DateTimeException which occurs during an error in printing.
Return Value: It returns the formatted date string and not null.
Below programs illustrate the format() method of LocalDate in Java:
Program 2: To illustrate the exception.
java.time.format.DateTimeParseException: Text '2018-01-32' could not be parsed: Invalid value for DayOfMonth (valid values 1 - 28/31): 32
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.