Java Date Time - Month getValue() example








Month getValue() gets the month-of-year int value.

Syntax

getValue has the following syntax.

public int getValue()

Example

The following example shows how to use getValue.

import java.time.LocalDate;
import java.time.Month;
/*from  w w w.  java2 s.  co  m*/
public class Main {
  public static void main(String[] args) {
    Month m = Month.from(LocalDate.now());
    System.out.println(m.getValue());
    System.out.println(m.name());
    System.out.println(m.ordinal());
  }
}

The code above generates the following result.