LocalDateTime getMonthValue() method in Java with Examples
The getMonthValue() method of LocalDateTime class is used to return the month-of-year field. This method returns the month from LocalDateTime as an int from 1 to 12.
Syntax:
public int getMonthValue()
Parameter: This method does not accept any parameter.
Returns: This method returns integer value which is the month-of-year field and it ranges from 1 to 12.
Below programs illustrate the LocalDateTime.getMonthValue() method:
Program 1:
import java.time.*;
public class GFG {
public static void main(String[] args)
{
LocalDateTime local
= LocalDateTime.parse( "2018-10-23T22:29:10" );
int monthvalue = local.getMonthValue();
System.out.println( "Month Value: "
+ monthvalue);
}
}
|
Program 2:
import java.time.*;
public class GFG {
public static void main(String[] args)
{
LocalDateTime local
= LocalDateTime.parse( "2018-12-13T12:28:13" );
int monthvalue = local.getMonthValue();
System.out.println( "Month Value: "
+ monthvalue);
}
}
|
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDateTime.html#getMonthValue()
Last Updated :
29 Nov, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...