OffsetTime format() method in Java with examples Last Updated : 13 Dec, 2018 Comments Improve Suggest changes Like Article Like Report 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 : Java // Java program to demonstrate the format() method import java.time.OffsetTime; import java.time.format.DateTimeFormatter; public class GFG { public static void main(String[] args) { // Parses the given time OffsetTime time = OffsetTime.parse("15:45:35+06:02"); // Prints the parsed time System.out.println("Time: " + time); // Function used DateTimeFormatter formatter = DateTimeFormatter.ISO_TIME; // Prints the formatted time System.out.println("Formatted time: " + formatter.format(time)); } } Output: Time: 15:45:35+06:02 Formatted time: 15:45:35+06:02 Program 2 : Java // Java program to demonstrate the format() method import java.time.OffsetTime; import java.time.format.DateTimeFormatter; public class GFG { public static void main(String[] args) { // Parses the given time OffsetTime time = OffsetTime.parse("11:14:13+07:05"); // Prints the parsed time System.out.println("Time: " + time); // Function used DateTimeFormatter formatter = DateTimeFormatter.ISO_TIME; // Prints the formatted time System.out.println("Formatted time: " + formatter.format(time)); } } Output: Time: 11:14:13+07:05 Formatted time: 11:14:13+07:05 Reference: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#format-java.time.format.DateTimeFormatter- Comment More infoAdvertise with us Next Article OffsetTime format() method in Java with examples G gopaldave Follow Improve Article Tags : Java Java-Functions Java-time package Java-OffsetTime Practice Tags : Java Similar Reads OffsetDateTime format() method in Java with examples The format() method of OffsetDateTime class in Java formats this date-time using the specified formatter. Syntax : public String format(DateTimeFormatter formatter) Parameter : This method accepts a single parameter formatter which specifies the formatter to use, not null.Return Value: It returns th 1 min read OffsetTime from() method in Java with examples The from() method of OffsetTime class in Java obtains an instance of OffsetTime from a temporal object which is passed in the parameter of the method. Syntax: public static OffsetTime from(TemporalAccessor temporal) Parameter: This method accepts a single mandatory parameter temporal which specifies 1 min read OffsetTime getHour() method in Java with examples The getHour() method of OffsetTime class in Java is used to get the value of the hour-of-day field from this OffsetTime instance. Syntax : public int getHour() Parameter : This method does not accepts any parameter. Return Value: It returns the hour-of-day which ranges from 0 to 23. Below programs i 1 min read OffsetTime of() method in Java with Examples The of(int hour, int minute, int second, int nanosecond, ZoneOffset offset) method of the OffsetTime class in Java is used to create an instance of OffsetTime from the passed values of hour, minute, second and nanosecond. In this method, we pass the value of hour, minute, second and nanosecond in in 2 min read OffsetTime getMinute() method in Java with examples The getMinute() method of OffsetTime class in Java is used to get the value of the minute field from this OffsetTime instance. Syntax : public int getMinute() Parameter : This method accepts does not accepts any parameters. Return Value: It returns the minute-of-hour which in range from 0 to 59. Bel 1 min read Like