LocalTime parse(CharSequence text, DateTimeFormatter formatter) example

Description

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;
//from   w w w  . j a v a2s . 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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset