LocalDate parse(CharSequence text) example

Description

LocalDate parse(CharSequence text) creates an instance of LocalDate from a text string such as 2007-12-03.

The string must represent a valid date and is parsed using DateTimeFormatter.ISO_LOCAL_DATE.

Syntax

parse has the following syntax.


public static LocalDate parse(CharSequence text)

Example

The following example shows how to use parse.


import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/*from   ww w  . j av a 2  s .  c  om*/
public class Main {
  public static void main(String[] args) {
    LocalDate a = LocalDate.parse("2007-12-03");
    
    System.out.println(a);
  }
}

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