Java Date Time Java Java API
java.time.LocalTime
public static LocalTime parse(CharSequence text)
Returns the LocalTime instance for the provided text. The text must be valid per DateTimeFormatter.ISO_LOCAL_TIME.
public static LocalTime parse(CharSequence text, DateTimeFormatter formatter)
public static LocalTime parse(CharSequence text,
DateTimeFormatter formatter)
Returns the LocalTime instance for the provided text and formatter. The provided text must be valid per DateTimeFormatter instance.
package com.logicbig.example.localtime;import java.time.LocalTime;import java.time.format.DateTimeFormatter;public class ParseExample { public static void main (String... args) { LocalTime t = LocalTime.parse("21:22"); System.out.println(t); t = LocalTime.parse("20:40", DateTimeFormatter.ISO_TIME); System.out.printf("ISO_TIME: %s%n",t); t = LocalTime.parse("02:30", DateTimeFormatter.ISO_LOCAL_TIME); System.out.printf("ISO_LOCAL_TIME: %s%n",t); }}
21:22ISO_TIME: 20:40ISO_LOCAL_TIME: 02:30
package com.logicbig.example.localtime;import java.time.LocalTime;import java.time.format.DateTimeFormatter;public class ParseExample2 { public static void main (String... args) { LocalTime t = LocalTime.parse( "22 11 30", DateTimeFormatter.ofPattern("HH mm ss")); System.out.println(t); t = LocalTime.parse( "10 11 30 PM", DateTimeFormatter.ofPattern("hh mm ss a")); System.out.println(t); }}
22:11:3022:11:30