java.time.YearMonth.until(Temporal endExclusive,TemporalUnit unit)方法根據指定的單位計算到另一個日期的時間量。
聲明
以下是java.time.YearMonth.until(Temporal endExclusive,TemporalUnit unit)方法的聲明。
public long until(Temporal endExclusive, TemporalUnit unit)
參數
endDateExclusive- 結束日期(包函),轉換為YearMonth,不為null。unit- 衡量總量的單位,而不是null。
返回值
此日期和結束日期之間的時間量。
例外
DateTimeException- 如果無法計算金額,或者結束時間不能轉換為YearMonth。UnsupportedTemporalTypeException- 如果不支持該單位。ArithmeticException- 如果發生數字溢出。
示例
以下示例顯示了java.time.YearMonth.until(Temporal endExclusive,TemporalUnit unit)方法的用法。
package com.zaixian;
import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
public class YearMonthDemo {
public static void main(String[] args) {
YearMonth date = YearMonth.parse("2015-12");
YearMonth date1 = YearMonth.now();
System.out.println(date.until(date1, ChronoUnit.YEARS));
}
}
編譯並運行上面的程式,這將產生以下結果 -
2
上一篇:
java.time.YearMonth類
下一篇:
java.time.ZonedDateTime類
