MonthDay atYear() method in Java with Examples
The atYear() method of MonthDay class in Java combines this month-day with a year to create a LocalDate.
Syntax:
public LocalDate atYear(int year)
Parameter: This method accepts a parameter year which specifies the year to use which is in range [MIN_YEAR, MAX_YEAR]
Returns: The function returns the local date formed from this month-day and the specified year, not null.
Below programs illustrate the MonthDay.atYear() method:
Program 1:
// Program to illustrate the atYear() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Parses the date MonthDay tm = MonthDay.parse("--12-06"); // Uses the function LocalDate dt = tm.atYear(2018); // Prints the date System.out.println(dt); } } |
2018-12-06
Program 2:
// Program to illustrate the atYear() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Parses the date MonthDay tm = MonthDay.parse("--01-01"); // Uses the function LocalDate dt = tm.atYear(2010); // Prints the date System.out.println(dt); } } |
2010-01-01
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/MonthDay.html#atYear-int-
Recommended Posts:
- MonthDay from() method in Java with Examples
- MonthDay get() method in Java with Examples
- MonthDay with() Method in Java with Examples
- MonthDay compareTo() method in Java with Examples
- MonthDay format() method in Java with Examples
- MonthDay getDayOfMonth() method in Java with Examples
- MonthDay equals() method in Java with Examples
- MonthDay isAfter() Method in Java with Examples
- MonthDay toString() Method in Java with Examples
- MonthDay isValidYear() Method in Java with Examples
- MonthDay isBefore() Method in Java with Examples
- MonthDay withDayOfMonth() Method in Java with Examples
- MonthDay adjustInto() method in Java with Examples
- MonthDay withMonth() Method in Java with Examples
- MonthDay getMonthValue() 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.



