YearMonth getMonth() method in Java Last Updated : 28 Nov, 2018 Comments Improve Suggest changes Like Article Like Report The getMonth() method of YearMonth class in Java is used to get the month field from this YearMonth instance with which it is used. It returns the month field as a Month instance. Syntax: public Month getMonth() Parameter: This method does not accepts any parameter. Return Value: It returns the month field from this YearMonth instance. Instead of returning a value, it returns a Month instance. Below programs illustrate the getMonth() method of YearMonth in Java: Program 1: Java // Program to illustrate the getMonth() method import java.util.*; import java.time.*; import java.time.format.DateTimeFormatter; public class GfG { public static void main(String[] args) { // Create a YearMonth object YearMonth thisYearMonth = YearMonth.of(2017, 8); // Get the month field System.out.println(thisYearMonth.getMonth()); } } Output: AUGUST Program 2: Java // Program to illustrate the getMonth() method import java.util.*; import java.time.*; import java.time.format.DateTimeFormatter; public class GfG { public static void main(String[] args) { // Create a YearMonth object YearMonth thisYearMonth = YearMonth.of(2018, 5); // Get the month field System.out.println(thisYearMonth.getMonth()); } } Output: MAY Reference: https://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html#getMonth-- Comment More infoAdvertise with us Next Article YearMonth format() method in Java G gopaldave Follow Improve Article Tags : Misc Java Java-Functions Java-time package Java-YearMonth +1 More Practice Tags : JavaMisc Similar Reads YearMonth getMonthValue() method in Java The getMonthValue() method of YearMonth class in Java is used to get the value of the month field from this YearMonth instance with which it is used. It returns the value of the month field as an integer between 1-12 denoting months from January to December. Syntax: public int getMonthValue() Parame 1 min read YearMonth atEndOfMonth() method in Java The atEndOfMonth() method of YearMonth class in Java is used to return a LocalDate of the last day of month based on this YearMonth object with which it is used. Syntax: public LocalDate atEndOfMonth() Parameter: This method does not accepts any parameter. Return Value: It returns a Local Date with 2 min read YearMonth getYear() method in Java The getYear() method of YearMonth class in Java is used to get the value of the Year field from this YearMonth instance with which it is used. It returns the value of the year field as an integer from MIN_YEAR to MAX_YEAR. Syntax: public int getYear() Parameter: This method does not accepts any para 1 min read Month getLong() method in Java The getLong() method is a built-in method of the Month ENUM which is used to get the value of the specified temporal field from this month instance as a long. Syntax: public long getLong(TemporalField field) Parameters: This method accepts a single parameter field whose long representation will be r 1 min read YearMonth format() method in Java The format() method of YearMonth class in Java is used to format this YearMonth instance according to a specified DateTimeFormatter for year-month passed as parameter to this method. Syntax: public String format(DateTimeFormatter formatter) Parameter: This method accepts a single parameter formatter 1 min read Month get() method in Java The get() method is a built-in method of the Month ENUM which is used to get the corresponding integral value of the month-of-year values specified by this Month instance. Syntax: public int get(TemporalField field) Parameters: This method accepts a single parameter which is a temporal object and ca 1 min read Like