java.time.ZonedDateTime.until(Temporal endExclusive,TemporalUnit unit)
方法根据指定的单位计算到另一个日期时间的时间量。
声明
以下是java.time.ZonedDateTime.until(Temporal endExclusive,TemporalUnit unit)
方法的声明。
public long until(Temporal endExclusive, TemporalUnit unit)
参数
endDateExclusive
- 结束日期(包函),转换为ZonedDateTime
,而不是null
。- `unit· - 衡量金额的单位,而不是空。
返回值
此日期时间与结束日期时间之间的时间量。
例外
DateTimeException
- 如果无法计算金额,或者结束时间不能转换为ZonedDateTime
。UnsupportedTemporalTypeException
- 如果不支持该单位。ArithmeticException
- 如果发生数字溢出。
示例
以下示例显示了java.time.ZonedDateTime.until(Temporal endExclusive,TemporalUnit unit)
方法的用法。
package com.yiibai;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
public class ZonedDateTimeDemo {
public static void main(String[] args) {
ZonedDateTime date = ZonedDateTime.parse("2017-03-28T12:25:38.492+05:30[Asia/Calcutta]");
ZonedDateTime date1 = ZonedDateTime.now();
System.out.println(date.until(date1, ChronoUnit.HOURS));
}
}
编译并运行上面的程序,这将产生以下结果 -
6603