目录

YearMonth minusYears(long yearsToSubtract)

描述 (Description)

java.time.YearMonth.minusYears(long yearsToSubtract)方法返回此YearMonth的副本,并减去指定的年份。

声明 (Declaration)

以下是java.time.YearMonth.minusYears(long yearsToSubtract)方法的声明。

public YearMonth minusYears(long yearsToSubtract)

参数 (Parameters)

yearsToSubtract - 减去,正面或负面的年份。

返回值 (Return Value)

基于此YearMonth的YearMonth减去指定的年份,而不是null。

异常 (Exception)

DateTimeException - 如果结果超出支持的范围。

例子 (Example)

以下示例显示了java.time.YearMonth.minusYears(long yearsToSubtract)方法的用法。

package com.iowiki;
import java.time.YearMonth;
import java.time.temporal.ChronoField;
public class YearMonthDemo {
   public static void main(String[] args) {
      YearMonth date = YearMonth.of(2017,12); 
      System.out.println(date.get(ChronoField.YEAR));
      System.out.println(date.minusYears(4).get(ChronoField.YEAR));
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

2017
2013
↑回到顶部↑
WIKI教程 @2018