java.time.MonthDay.atYear() Method Example



Description

The java.time.MonthDay.atYear(int year) method combines this month-day with a year to create a LocalDate.

Declaration

Following is the declaration for java.time.MonthDay.atYear(int year) method.

public LocalDate atYear(int year)

Parameters

year − the year to use, from MIN_YEAR to MAX_YEAR.

Return Value

the local date formed from this month-day and the specified year, not null.

Exceptions

DateTimeException − if the year is outside the valid range of years.

Example

The following example shows the usage of java.time.MonthDay.atYear(int year) method.

package com.tutorialspoint;

import java.time.LocalDate;
import java.time.MonthDay;

public class MonthDayDemo {
   public static void main(String[] args) {

      MonthDay time = MonthDay.parse("--12-30");
      LocalDate date = time.atYear(2017);
      System.out.println(date);  
   }
}

Let us compile and run the above program, this will produce the following result −

2017-12-30
Advertisements