java.time.YearMonth.atDay() Method Example



Description

The java.time.YearMonth.atDay(int dayOfMonth) method combines this year-month with a day-of-month to create a LocalDate.

Declaration

Following is the declaration for java.time.YearMonth.atDay(int dayOfMonth) method.

public LocalDate atDay(int dayOfMonth)

Parameters

dayOfMonth − the day-of-month to use, from 1 to 31.

Return Value

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

Exception

DateTimeException − if the day is invalid for the year-month.

Example

The following example shows the usage of java.time.YearMonth.atDay(int dayOfMonth) method.

package com.tutorialspoint;

import java.time.LocalDate;
import java.time.YearMonth;

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

      YearMonth year = YearMonth.of(2015,12);
      
      LocalDate date = year.atDay(26);
      System.out.println(date);  
   }
}

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

2015-12-26
Advertisements