LocalTime parse(CharSequence text) example

Description

LocalTime parse(CharSequence text) gets an instance of LocalTime from a text string such as 10:15.

The string must represent a valid time and is parsed using DateTimeFormatter.ISO_LOCAL_TIME.

Syntax

parse has the following syntax.


public static LocalTime parse(CharSequence text)

Example

The following example shows how to use parse.


import java.time.LocalTime;
//from  w  ww . j a v a  2 s  . c  o  m
public class Main {
  public static void main(String[] args) {
    LocalTime l = LocalTime.parse("12:34");
    
    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