Java Date Time - YearMonth withYear(int year) example








YearMonth withYear(int year) returns a copy of this YearMonth with the year altered.

Syntax

withYear has the following syntax.

public YearMonth withYear(int year)

Example

The following example shows how to use withYear.

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

  }
}

The code above generates the following result.