The format() method of OffsetTime class in Java formats this time using the specified formatter which is passed in the parameter of the function.
Syntax:
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
Recommended Posts:
- OffsetTime plus() method in Java with examples
- OffsetTime now() method in Java with examples
- OffsetTime get() method in Java with examples
- OffsetTime from() method in Java with examples
- OffsetTime parse() method in Java with examples
- OffsetTime ofInstant() method in Java with examples
- OffsetTime plusHours() method in Java with examples
- OffsetTime minus() method in Java with examples
- OffsetTime getLong() method in Java with examples
- OffsetTime isEqual() method in Java with examples
- OffsetTime atDate() method in Java with examples
- OffsetTime getMinute() method in Java with examples
- OffsetTime plusNanos() method in Java with Examples
- OffsetTime toString() method in Java with examples
- OffsetTime plusMinutes() method in Java with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



