MonthDay getMonthValue() method in Java with Examples
The getMonthValue() method of MonthDay class in Java gets the month-of-year field from 1 to 12.
Syntax:
public int getMonthValue()
Parameter: This method accepts no parameters.
Returns: The function returns the month-of-year, from 1 to 12.
Below programs illustrate the MonthDay.getMonthValue() method:
Program 1:
// Program to illustrate the getMonthValue() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Parses the date MonthDay tm1 = MonthDay.parse("--12-06"); // Uses the function LocalDate dt1 = tm1.atYear(2018); // Prints the date System.out.println(dt1.getMonthValue()); } } |
chevron_right
filter_none
Output:
12
Program 2:
// Program to illustrate the getMonthValue() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Parses the date MonthDay tm1 = MonthDay.parse("--01-09"); // Uses the function LocalDate dt1 = tm1.atYear(2016); // Prints the date System.out.println(dt1.getMonthValue()); } } |
chevron_right
filter_none
Output:
1
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/MonthDay.html#getMonthValue–
Recommended Posts:
- ZonedDateTime getMonthValue() method in Java with Examples
- OffsetDateTime getMonthValue() method in Java with examples
- LocalDate getMonthValue() method in Java with Examples
- LocalDateTime getMonthValue() method in Java with Examples
- MonthDay get() method in Java with Examples
- MonthDay from() method in Java with Examples
- MonthDay with() Method in Java with Examples
- MonthDay query() method in Java with Examples
- MonthDay hashCode() method in Java with Examples
- MonthDay isAfter() Method in Java with Examples
- MonthDay getMonth() method in Java with Examples
- MonthDay range() method in Java with Examples
- MonthDay isValidYear() Method in Java with Examples
- MonthDay getLong() method in Java with Examples
- MonthDay isBefore() Method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



