YearMonth format(DateTimeFormatter formatter) example
Description
YearMonth format(DateTimeFormatter formatter)
formats this year-month using the specified formatter.
Syntax
format
has the following syntax.
public String format(DateTimeFormatter formatter)
Example
The following example shows how to use format
.
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
//w ww . j ava 2 s. co m
public class Main {
public static void main(String[] args) {
YearMonth y = YearMonth.now();
String s = y.format(DateTimeFormatter.ofPattern("yyyy MM"));
System.out.println(s);
}
}
The code above generates the following result.