Java Instant isBefore() 方法

7 Jan 2025 | 1 分钟阅读

Java Instant 类的 isBefore() 方法用于检查该 Instant 是否在指定的 Instant 之前。

语法

参数

otherInstant - 要与之比较的另一个 Instant,不能为空。

返回

如果此 Instant 在指定的 Instant 之后,则返回 True。

异常

NullPointerException - 如果 otherInstant 为 null。

示例 1

输出

输出将如下所示。

Instant 1: 2017-02-03T10:37:30Z
Instant 2: 2017-03-03T10:37:30Z
Instant 1 is not after as Instant 2.

示例 2

输出

输出将如下所示。

2017-05-01T20:57:49.381Z
2016-12-03T10:15:30Z
false