java.time.Year.until(Temporal endExclusive,TemporalUnit unit)
方法根据指定的单位计算到另一个日期的时间量。
声明
以下是java.time.Year.until(Temporal endExclusive,TemporalUnit unit)
方法的声明。
public long until(Temporal endExclusive, TemporalUnit unit)
参数
endDateExclusive
- 结束日期(包含),转换为Year
,而不是null
。unit
- 衡量总数的单位,而不是null
。
返回值
此日期和结束日期之间的时间量。
异常
DateTimeException
- 如果无法计算金额,或者结束时间不能转换为Year。UnsupportedTemporalTypeException
- 如果不支持该单位。ArithmeticException
- 如果发生数字溢出。
示例
以下示例显示了java.time.Year.until(Temporal endExclusive,TemporalUnit unit)
方法的用法。
package com.zaixian;
import java.time.Year;
import java.time.temporal.ChronoUnit;
public class YearDemo {
public static void main(String[] args) {
Year date = Year.parse("2015");
Year date1 = Year.now();
System.out.println(date.until(date1, ChronoUnit.YEARS));
}
}
编译并运行上面的程序,这将产生以下结果 -
1
上一篇:
java.time.Year类
下一篇:
java.time.YearMonth类