java.time.OffsetDateTime.minusYears(long yearsToSubtract)
方法返回此OffsetDateTime
的副本,并减去指定的年份。
声明
以下是java.time.OffsetDateTime.minusYears(long yearsToSubtract)
方法的声明。
public OffsetDateTime minusYears(long yearsToSubtract)
参数
yearsToSubtract
- 减去的年份,可能是负数。
返回值
基于此日期时间的OffsetDateTime
,减去年份,而不是null
。
异常
DateTimeException
- 如果结果超出支持的日期范围。
示例
以下示例显示了java.time.OffsetDateTime.minusYears(long yearsToSubtract)
方法的用法。
package com.zaixian;
import java.time.OffsetDateTime;
public class OffsetDateTimeDemo {
public static void main(String[] args) {
OffsetDateTime date = OffsetDateTime.parse("2017-02-03T12:30:30+01:00");
System.out.println(date.minusYears(2));
}
}
编译并运行上面的程序,这将产生以下结果 -
2015-02-03T12:30:30+01:00