Java Date Time - LocalTime parse(CharSequence text, DateTimeFormatter formatter) example








LocalTime parse(CharSequence text, DateTimeFormatter formatter) gets an instance of LocalTime from a string using a specific formatter.

Syntax

parse has the following syntax.

public static LocalTime parse(CharSequence text,   DateTimeFormatter formatter)

Example

The following example shows how to use parse.

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
// ww w  .j a  v  a2 s  . co  m
public class Main {
  public static void main(String[] args) {
    LocalTime l = LocalTime.parse("12:34",DateTimeFormatter.ISO_LOCAL_TIME);
    
    System.out.println(l);
  }
}

The code above generates the following result.