Java YearMonth get number of days in each month

Description

Java YearMonth get number of days in each month

import java.time.Month;
import java.time.YearMonth;

public class Main {
  public static void main(String[] args) {
    int year = 2020;

    System.out.printf("For the year %d:%n", year);
    for (Month month : Month.values()) {
      YearMonth ym = YearMonth.of(year, month);
      System.out.printf("%s: %d days%n", month, ym.lengthOfMonth());
    }/*from  www . ja  v a 2  s .co  m*/
  }
}



PreviousNext

Related