java.time.YearMonth.with() 方法
描述
java.time.YearMonth.with(TemporalAdjusteradjuster) 方法返回今年的调整副本。
声明
以下是 java.time.YearMonth.with(TemporalAdjuster adjuster) 方法的声明。
public YearMonth with(TemporalAdjuster adjuster)
参数
adjuster − 要使用的调节器,不为空。
返回值
基于此的 YearMonth 进行了调整,而不是 null。
异常
DateTimeException − 如果无法进行调整。
ArithmeticException − 如果发生数字溢出。
示例
下面的例子展示了 java.time.YearMonth.with(TemporalAdjuster adjuster) 方法的使用。
package com.tutorialspoint;
import java.time.YearMonth;
public class YearMonthDemo {
public static void main(String[] args) {
YearMonth date = YearMonth.parse("2017-12");
YearMonth result = date.with(YearMonth.of(2010,12));
System.out.println(result);
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
2010-12

