Java MonthDay class

Introduction

Java MonthDay class represents month and a day of month, for example, -12-15.

    /*from   w w  w  . j av a2 s .c  o  m*/
import java.time.Month;
import java.time.MonthDay;

public class Main {
  public static void main(String[] args) {
    // Use MonthDay
    MonthDay md1 = MonthDay.of(Month.DECEMBER, 25);
    System.out.println(md1);
    MonthDay md2 = MonthDay.of(Month.FEBRUARY, 29);
    System.out.println(md2);
    if (md2.isValidYear(2009)) {
      System.out.println(md2 + " occurred in 2009");
    } else {
      System.out.println(md2 + " did not occur in 2009");
    }

  }
}



PreviousNext

Related