LocalTime parse() method in Java with Examples Last Updated : 27 Jan, 2022 Comments Improve Suggest changes Like Article Like Report 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 parsed using DateTimeFormatter.ISO_LOCAL_TIME.Syntax: public static LocalTime parse(CharSequence text) Parameters: This method accepts only one parameter text which is the text to parse in LocalTime. It should not be null.Return value: This method returns LocalTime which is the parsed local date-time.Exception: This method throws DateTimeParseException if the text cannot be parsed.Below programs illustrate the parse() method: Program 1: Java // Java program to demonstrate // LocalTime.parse() method import java.time.*; public class GFG { public static void main(String[] args) { // create an LocalTime object LocalTime lt = LocalTime.parse("10:15:45"); // print result System.out.println("LocalTime : " + lt); } } Output: LocalTime : 10:15:45 parse(CharSequence text, DateTimeFormatter formatter) parse() method of a LocalTime class used to get an instance of LocalTime from a string such as '10:15:45' passed as parameter using a specific formatter.The date-time is parsed using a specific formatter.Syntax: public static LocalTime parse(CharSequence text, DateTimeFormatter formatter) Parameters: This method accepts two parameters text which is the text to parse and formatter which is the formatter to use.Return value: This method returns LocalTime which is the parsed local date-time.Exception: This method throws DateTimeParseException if the text cannot be parsed.Below programs illustrate the parse() method: Program 1: Java // Java program to demonstrate // LocalTime.parse() method import java.time.*; import java.time.format.*; public class GFG { public static void main(String[] args) { // create a formatter DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_TIME; // create an LocalTime object and LocalTime lt = LocalTime .parse("10:15:45", formatter); // print result System.out.println("LocalTime : " + lt); } } Output: LocalTime : 10:15:45 References: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#parse(java.lang.CharSequence) https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#parse(java.lang.CharSequence, java.time.format.DateTimeFormatter) Comment More infoAdvertise with us Next Article LocalTime parse() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-time package Java-LocalTime Practice Tags : Java Similar Reads LocalDate parse() method in Java with Examples In LocalDate class, there are two types of parse() method depending upon the parameters passed to it. parse(CharSequence text) parse() method of a LocalDate class used to get an instance of LocalDate from a string such as '2018-10-23' passed as parameter.The string must have a valid date-time and is 2 min read Level parse() method in Java with Examples The parse() method of java.util.logging.Level is used to parse a level name string into a Level. The name of the logging level must be a valid logging name. The argument string may consist of either a level name or an integer value. Level example name: "INFO", "800". Syntax: public static Level pars 2 min read Scanner locale() method in Java with Examples The locale() method of java.util.Scanner class returns this scanner's locale. Syntax: public Locale locale() Parameters: The function does not accepts any parameter. Return Value: This function returns this scanner's locale Below programs illustrate the above function: Program 1: Java // Java progra 1 min read Locale toString() Method in Java with Examples The toString() method of Locale class in Java is used to return a string representation of this locale. Each element i.e., the language, country or the variant of the locale is separated by underbars Syntax: LOCALE.toString() Parameters: This method does not take any parameters. Return Value: This m 1 min read LocalDateTime toLocalDate() method in Java with Examples The toLocalDate() method of LocalDateTime class is used to get the LocalDate representation of this LocalDateTime. This method is derived from the Object Class and behaves in the similar way. Syntax: public LocalDate toLocalDate() Parameter: This method takes no parameters. Returns: This method retu 1 min read Like