Java Date Time - MonthDay withDayOfMonth(int dayOfMonth) example








MonthDay withDayOfMonth(int dayOfMonth) returns a copy of this MonthDay with the day-of-month altered.

Syntax

withDayOfMonth has the following syntax.

public MonthDay withDayOfMonth(int dayOfMonth)

Example

The following example shows how to use withDayOfMonth.

import java.time.MonthDay;
//from www.ja  v a2  s.c  o  m
public class Main {
  public static void main(String[] args) {
    MonthDay m = MonthDay.now();
    MonthDay n = m.withDayOfMonth(21);
    System.out.println(n);

  }
}

The code above generates the following result.