Year atMonthDay() method in Java Last Updated : 27 Nov, 2018 Comments Improve Suggest changes Like Article Like Report The atMonthDay(MonthDay) method of Year class in Java combines the current year object with a month-day object passed as parameter to it to create a LocalDate object. Syntax: public LocalDate atMonthDay(MonthDay monthDay) Parameter: This method accepts a single parameter monthDay. It is the MonthDay object which specifies a month-day to use. It takes a valid MonthDay object and cannot be NULL. Return Value: It returns a LocalDate object formed by the current year object and a valid MonthDate object passed as parameter to the function. Note: If the current year is not a leap year and the MonthDay object passed as parameter specifies "29th February", it will be automatically rounded to "28th February" in the resulting LocalDate object. Below programs illustrate the atMonthDay(MonthDay) method of Year in Java: Program 1: Java // Program to illustrate the atMonthDay(MonthDay) method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Creates a Year object Year thisYear = Year.of(2017); // Creates a MonthDay object MonthDay monthDay = MonthDay.of(9, 15); // Creates a LocalDate with this // Year object and MonthDay passed to it LocalDate date = thisYear.atMonthDay(monthDay); System.out.println(date); } } Output: 2017-09-15 Program 2: Since 2018 is not a leap year, the day 29 will be rounded off to 28 in the below program. Java // Program to illustrate the atMonthDay(MonthDay) method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Creates a Year object Year thisYear = Year.of(2018); // Creates a MonthDay object MonthDay monthDay = MonthDay.of(2, 29); // Creates a LocalDate with this // Year object and MonthDay passed to it LocalDate date = thisYear.atMonthDay(monthDay); System.out.println(date); } } Output: 2018-02-28 Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Year.html#atMonthDay-java.time.MonthDay- Comment More infoAdvertise with us Next Article Year atDay() method in Java B barykrg Follow Improve Article Tags : Misc Java Java-Functions Java-time package Java-Year +1 More Practice Tags : JavaMisc Similar Reads Year atDay() method in Java The atDay() method of Year class in Java combines the current year with a day-of-year passed as parameter to it to create a LocalDate. Syntax: public LocalDate atDay(int dayOfYear) Parameter: This method accepts a single parameter dayOfYear. It is the day-of-year to use. It can take values from 1 to 2 min read Year atMonth(int) method in Java The atMonth(int) method of Year class in Java combines the current year object with a month passed as parameter to it to create a YearMonth object. Syntax: public YearMonth atMonth(int month) Parameter: This method accepts a single parameter month. It is the month-of-year to use. It takes an integer 2 min read Year atMonth(int) method in Java The atMonth(int) method of Year class in Java combines the current year object with a month passed as parameter to it to create a YearMonth object. Syntax: public YearMonth atMonth(int month) Parameter: This method accepts a single parameter month. It is the month-of-year to use. It takes an integer 2 min read YearMonth atDay() method in Java The atDay() method of YearMonth class in Java combines the current year-month with a day-of-month passed as parameter to it to create a LocalDate. Syntax: public LocalDate atDay(int dayOfMonth) Parameter: This method accepts a single parameter dayOfMonth. It is the day-of-month to use. It can take v 2 min read YearMonth getMonth() method in Java 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 mont 1 min read YearMonth getMonth() method in Java 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 mont 1 min read Like