MonthDay of(Month, int) method in Java with Examples Last Updated : 12 May, 2020 Comments Improve Suggest changes Like Article Like Report The of(Month month, int dayOfMonth) method of the MonthDay class in Java is used to get an instance of MonthDay. Syntax: public static MonthDay of( Month month, int dayOfMonth) Parameters: This method accepts two parameters: month: It represents the month of year. dayOfMonth: It represents the day of month. Return value: This method returns the month-day. Exceptions: This method throws DateTimeException if the value of any field is out of range or the day of month is invalid for the month. Below programs illustrate the of(Month month, int dayOfMonth) method of MonthDay in Java: Program 1: Java // Java program to demonstrate // MonthDay.of(Month month, int dayOfMonth) method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // apply of(Month month, int dayOfMonth) method // of MonthDay class MonthDay monthday = MonthDay.of(Month.MAY, 9); // print both month and day System.out.println("MonthDay: " + monthday); } } Output: MonthDay: --05-09 Program 2: Java // Java program to demonstrate // MonthDay.of(Month month, int dayOfMonth) method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // apply of(Month month, int dayOfMonth) method // of MonthDay class MonthDay monthday = MonthDay.of(Month.MAY, 9); // print only month System.out.println("Month: " + monthday.getMonth()); } } Output: Month: MAY References: https://docs.oracle.com/javase/10/docs/api/java/time/MonthDay.html#of(java.time.Month, int) Comment More infoAdvertise with us Next Article YearMonth of(int, Month) method in Java with Examples P pp_pankaj Follow Improve Article Tags : Java Java-Functions Java-MonthDay Practice Tags : Java Similar Reads MonthDay of(int, int) method in Java with Examples The of(int. int) method of the MonthDay class in Java is used to get an instance of MonthDay. Syntax: public static MonthDay of( int month, int dayOfMonth) Parameters: This method accepts two parameters: month: It represents the month of year. dayOfMonth: It represents the day of month. Return value 2 min read MonthDay get() method in Java with Examples The get() method of MonthDay class in Java gets the value of the specified field from this month-day as an int. Syntax: public int get(TemporalField field) Parameter: This method accepts a parameter field which specifies the field to get and not null. Returns: The function returns the value for the 2 min read YearMonth of(int, Month) method in Java with Examples The of(int year, Month month) method of the YearMonth class in Java is used to get an instance of YearMonth from a year and month. Syntax: public static YearMonth of( int year, Month month) Parameters: This method accepts two parameters: year: It represents year. month: It represents the month of ye 2 min read MonthDay getMonth() method in Java with Examples The getMonth() method of MonthDay class in Java obtains an instance of MonthDay from a temporal object. Syntax: public Month getMonth() Parameter: This method accepts no parameters. Returns: The function returns the month-of-year and not null. Below programs illustrate the MonthDay.getMonth() method 1 min read MonthDay toString() Method in Java with Examples toString() method of the MonthDay class used to represents this month-day as a String like --08-23.The output will be in the format --MM-dd:Syntax: public String toString() Parameters: This method did not accepts any parameter.Return value: This method returns a String representation of this MonthDa 1 min read MonthDay format() method in Java with Examples The format() method of MonthDay class in Java formats this month-day using the specified formatter. Syntax: public String format(DateTimeFormatter formatter) Parameter: This method accepts a parameter formatter which specifies the formatter to use and it is not null. Returns: The function returns th 1 min read Like