YearMonth atDay(int dayOfMonth) example

Description

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

Syntax

atDay has the following syntax.


public LocalDate atDay(int dayOfMonth)

Example

The following example shows how to use atDay.


import java.time.LocalDate;
import java.time.YearMonth;
// ww w  .j a va  2s  . c om
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    LocalDate l = y.atDay(2);
    System.out.println(l);

  }
}

The code above generates the following result.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset