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:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
MonthDay tm1 = MonthDay.parse( "--12-06" );
LocalDate dt1 = tm1.atYear( 2018 );
System.out.println(dt1.getMonthValue());
}
}
|
Program 2:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
MonthDay tm1 = MonthDay.parse( "--01-09" );
LocalDate dt1 = tm1.atYear( 2016 );
System.out.println(dt1.getMonthValue());
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/MonthDay.html#getMonthValue–