Java Data Type How to - Create MonthDay from month and day








Question

We would like to know how to create MonthDay from month and day.

Answer

import java.time.Month;
import java.time.MonthDay;
/*from   w  ww .jav a  2  s . co  m*/
public class Main {

  public static void main(String[] args) {
    Month month = Month.JULY;
    int dayOfMonth = 14;

    MonthDay jugIL = MonthDay.of(month, dayOfMonth);

    System.out.println(jugIL);
  }
}

The code above generates the following result.