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.