YearMonth parse(CharSequence text, DateTimeFormatter formatter) example

Description

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

Syntax

parse has the following syntax.


public static YearMonth parse(CharSequence text,   DateTimeFormatter formatter)

Example

The following example shows how to use parse.


import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
/* w w  w .  java 2s .com*/
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.parse("2013 09",DateTimeFormatter.ofPattern("yyyy MM"));
    
    System.out.println(y);

  }
}

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