OffsetTime format() method in Java with examples
The format() method of OffsetTime class in Java formats this time using the specified formatter which is passed in the parameter of the function.
public String format(DateTimeFormatter formatter)
Parameter: This method accepts a single mandatory parameter formatter which specifies the formatter to be used and it is not null.
Return Value: It returns the formatted date string and it is not null.
Exceptions: The function returns DateTimeException which is thrown by the method when an error occurs during printing.
Below programs illustrate the format() method:
Program 1 :
Time: 15:45:35+06:02 Formatted time: 15:45:35+06:02
Program 2 :
Time: 11:14:13+07:05 Formatted time: 11:14:13+07:05
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.