YearMonth parse(CharSequence text, DateTimeFormatter formatter)
creates an instance of YearMonth from a text string using a specific formatter.
parse
has the following syntax.
public static YearMonth parse(CharSequence text, DateTimeFormatter formatter)
The following example shows how to use parse
.
import java.time.YearMonth; import java.time.format.DateTimeFormatter; //from ww w.java 2 s. co m 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.