Java Date Time - YearMonth withMonth(int month) example








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

Syntax

withMonth has the following syntax.

public YearMonth withMonth(int month)

Example

The following example shows how to use withMonth.

import java.time.YearMonth;
//w w w. ja v  a 2s.c  o m
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    YearMonth s = y.withMonth(3);
    System.out.println(s);

  }
}

The code above generates the following result.