YearMonth withYear(int year) example
Description
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;
/*from w w w . j ava2 s .c om*/
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.