MonthDay atYear() method in Java with Examples
Last Updated :
06 Dec, 2018
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:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
MonthDay tm = MonthDay.parse( "--12-06" );
LocalDate dt = tm.atYear( 2018 );
System.out.println(dt);
}
}
|
Program 2:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
MonthDay tm = MonthDay.parse( "--01-01" );
LocalDate dt = tm.atYear( 2010 );
System.out.println(dt);
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/MonthDay.html#atYear-int-
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...