Java LocalDate getMonthValue() Method
Example
Get the month of a date, as a number:
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate myDate = LocalDate.of(2026, 1, 15);
System.out.println(myDate.getMonthValue());
}
}
Definition and Usage
The getMonthValue() method returns the month of the date as a number, from 1 (January) to 12 (December).
Tip: Use getMonth() to get the month as a Month value, like JANUARY.
Syntax
public int getMonthValue()
Parameter Values
None.
Technical Details
| Returns: | The month, as a number from 1 to 12. |
|---|
Related Pages
❮ Date and Time Methods