YearMonth format(DateTimeFormatter formatter)
formats this year-month using the specified formatter.
format
has the following syntax.
public String format(DateTimeFormatter formatter)
The following example shows how to use format
.
import java.time.YearMonth; import java.time.format.DateTimeFormatter; /*from www . j av a 2s. c om*/ 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.