首页javadate_formatJava Data Type - 如何将"Year Month"设置为"201506"

Java Data Type - 如何将"Year Month"设置为"201506"

我们想知道如何将"Year Month"设置为"201506"。
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;

public class Main {

  public static void main(String[] args) {

    System.out.println(toUUUUMM(YearMonth.now()));
  }

  public static String toUUUUMM(YearMonth yearAndMonth) {
    return yearAndMonth.format(DateTimeFormatter.ofPattern("uuuuMM"));
  }
}