Java Date Time - MonthDay withMonth(int month) example








MonthDay withMonth(int month) returns a copy of this MonthDay with the month-of-year altered.

Syntax

withMonth has the following syntax.

public MonthDay withMonth(int month)

Example

The following example shows how to use withMonth.

import java.time.MonthDay;
//from   w  ww. ja v a 2  s. com
public class Main {
  public static void main(String[] args) {
    MonthDay m = MonthDay.now();
    MonthDay n = m.withMonth(1);
    System.out.println(n);

  }
}

The code above generates the following result.