YearMonth withMonth(int month)
returns a copy of this YearMonth with the month-of-year altered.
withMonth
has the following syntax.
public YearMonth withMonth(int month)
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.