The format() method of a LocalTime class is used to format this time using the specified formatter passed as a parameter. This method formats this time based on passed formatter to a string.
public String format(DateTimeFormatter formatter)
Parameters: This method accepts a single parameter formatter which is the specified formatter. It should not be null.
Return value: This method returns the formatted time string.
Exception: This method throws a DateTimeException if an error occurs during printing.
Below programs illustrate the format() method:
value : 03:18:23
value : 23:59:59
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.