描述
这个java.time.OffsetDateTime.until(Temporal endExclusive, TemporalUnit unit)方法根据指定的单位计算另一个日期时间之前的时间量。
声明
以下是声明java.time.OffsetDateTime.until(Temporal endExclusive, TemporalUnit unit)方法。
public long until(Temporal endExclusive, TemporalUnit unit)
参数
endDateExclusive− 结束日期,独占,转换为 OffsetDateTime,不为空。
unit− 计量数量的单位,不为空。
返回值
此日期时间和结束日期时间之间的时间量。
异常
DateTimeException- 如果数量无法计算,或者结束时间无法转换为 OffsetDateTime。
UnsupportedTemporalTypeException− 如果不支持该单元。
ArithmeticException- 如果发生数字溢出。
示例
下面的例子展示了 java.time.OffsetDateTime.until(Temporal endExclusive, TemporalUnit unit) 方法的用法。
package com.tutorialspoint;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
public class OffsetDateTimeDemo {
public static void main(String[] args) {
OffsetDateTime date = OffsetDateTime.parse("2017-01-03T10:15:30+01:00");
OffsetDateTime date1 = OffsetDateTime.now();
System.out.println(date.until(date1, ChronoUnit.HOURS));
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
8566
相关用法
- Java java.time.OffsetDateTime.now()用法及代码示例
- Java java.time.OffsetDateTime.withSecond()用法及代码示例
- Java java.time.OffsetDateTime.plus()用法及代码示例
- Java java.time.OffsetDateTime.equals()用法及代码示例
- Java java.time.OffsetDateTime.getLong()用法及代码示例
- Java java.time.OffsetDateTime.withHour()用法及代码示例
- Java java.time.OffsetDateTime.minusSeconds()用法及代码示例
- Java java.time.OffsetDateTime.withNano()用法及代码示例
- Java java.time.OffsetDateTime.getDayOfMonth()用法及代码示例
- Java java.time.OffsetDateTime.minusYears()用法及代码示例
- Java java.time.OffsetDateTime.getNano()用法及代码示例
- Java java.time.OffsetDateTime.getDayOfWeek()用法及代码示例
- Java java.time.OffsetDateTime.plusWeeks()用法及代码示例
- Java java.time.OffsetDateTime.getYear()用法及代码示例
- Java java.time.OffsetDateTime.withOffsetSameInstant()用法及代码示例
- Java java.time.OffsetDateTime.plusMinutes()用法及代码示例
- Java java.time.OffsetDateTime.getMinute()用法及代码示例
- Java java.time.OffsetDateTime.minusMonths()用法及代码示例
- Java java.time.OffsetDateTime.isSupported()用法及代码示例
- Java java.time.OffsetDateTime.truncatedTo()用法及代码示例
注:本文由纯净天空筛选整理自 java.time.OffsetDateTime.until() Method Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。