LocalTime format() method in Java with Examples Last Updated : 03 Dec, 2018 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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: Program 1: Java // Java program to demonstrate // LocalTime.format() method import java.time.*; import java.time.format.DateTimeFormatter; public class GFG { public static void main(String[] args) { // create a LocalTime Objects LocalTime time = LocalTime.parse("03:18:23"); // create formatter Object DateTimeFormatter formatter = DateTimeFormatter.ISO_TIME; // apply format String value = time.format(formatter); // print result System.out.println("value : " + value); } } Output: value : 03:18:23 Program 2: Java // Java program to demonstrate // LocalTime.format() method import java.time.*; import java.time.format.DateTimeFormatter; public class GFG { public static void main(String[] args) { // create a LocalTime Objects LocalTime time = LocalTime.parse("23:59:59"); // create formatter Object for ISO_LOCAL_TIME DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_TIME; // apply format String value = time.format(formatter); // print result System.out.println("value : " + value); } } Output: value : 23:59:59 Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#format(java.time.format.DateTimeFormatter) Comment More infoAdvertise with us Next Article LocalTime format() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-time package Java-LocalTime Practice Tags : Java Similar Reads Formatter locale() method in Java with Examples The locale() method is a built-in method of the java.util.Formatter which returns a locale. This locale is set by the formatter construction. The format method for this object which has a locale argument does not change this value. Syntax: public Locale locale() Parameters: The function accepts no p 2 min read LocalTime parse() method in Java with Examples In LocalTime class, there are two types of parse() method depending upon the parameters passed to it. parse(CharSequence text) parse() method of a LocalTime class used to get an instance of LocalTime from a string such as '10:15:45' passed as parameter.The string must have a valid date-time and is p 2 min read LocalDate getYear() method in Java with Examples The getYear() method of LocalDate class in Java gets the year field. Syntax: public int getYear() Parameter: This method does not accepts any parameter. Return Value: The function returns the year, from MIN_YEAR to MAX_YEAR Below programs illustrate the getYear() method of LocalDate in Java: Program 1 min read LocalTime toString() method in Java with Examples The toString() method of LocalTime class is used to represents this time as a String, such as 20:15:34.111. Following ISO-8601 formats are used for representation: HH:mm HH:mm:ss HH:mm:ss.SSS HH:mm:ss.SSSSSS HH:mm:ss.SSSSSSSSS This method is derived from the Object Class and behaves in a similar way 1 min read Year format() method in Java with Examples The format() method of Year class in Java is used to format the current Year object according to the DateTimeFormatter passed to it as a parameter. Syntax: public String format(DateTimeFormatter formatter) Parameter: This method accepts a single parameter formatter. It specifies a DateTimeFormatter 2 min read Like