Year parse(CharSequence text, DateTimeFormatter formatter) example
Description
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 av a 2 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.