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








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

Syntax

parse has the following syntax.

public static Year parse(CharSequence text,   DateTimeFormatter formatter)

Example

The following example shows how to use parse.

import java.time.Year;
import java.time.format.DateTimeFormatter;
/*from  w  w w . j a v a2  s.c o  m*/
public class Main {
  public static void main(String[] args) {
    Year y = Year.parse("2014",DateTimeFormatter.ofPattern("yyyy"));
    System.out.println(y);

  }
}

The code above generates the following result.