LocalDateTime getMonth() method in Java with Examples
The getMonth() method of an LocalDateTime class is used to return month-of-year field. This field is returned using the Month enum. The enum can provide the primitive int value.
Syntax:
public Month getMonth()
Parameter: This method does not accept any parameter.
Returns: This method returns the enum Month for the month of this LocalDateTime.
Below programs illustrate the LocalDateTime.getMonth() method:
Program 1:
// Java program to demonstrate // LocalDateTime.getMonth() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalDateTime Object LocalDateTime local = LocalDateTime.parse("2007-12-02T22:48:29"); // get Month enum value field Month month = local.getMonth(); // print result System.out.println("Month: " + month); } } |
Month: DECEMBER
Program 2:
// Java program to demonstrate // LocalDateTime.getMonth() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalDateTime Object LocalDateTime local = LocalDateTime.parse("2017-07-22T09:32:42"); // get Month enum value field Month month = local.getMonth(); // print result System.out.println("Month: " + month); } } |
Month: JULY
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDateTime.html#getMonth()
Recommended Posts:
- OffsetDateTime getMonth() method in Java with examples
- MonthDay getMonth() method in Java with Examples
- ZonedDateTime getMonth() method in Java with Examples
- LocalDateTime with() Method in Java with Examples
- LocalDateTime until() Method in Java with Examples
- LocalDateTime now() Method in Java with Examples
- LocalDateTime from() method in Java with Examples
- LocalDateTime plus() method in Java with Examples
- LocalDateTime plusHours() method in Java with Examples
- LocalDateTime withSecond() method in Java with Examples
- LocalDateTime plusYears() method in Java with Examples
- LocalDateTime plusMonths() method in Java with Examples
- LocalDateTime equals() method in Java with Examples
- LocalDateTime plusNanos() method in Java with Examples
- LocalDateTime plusSeconds() 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.



