Javatime-instant-isafter
提供:Dev Guides
java.time.Instant.isAfter()メソッドの例
説明
- java.time.Instant.isAfter(Instant otherInstant)*メソッドは、このインスタントが指定されたインスタントの後かどうかをチェックします。
宣言
以下は* java.time.Instant.isAfter(Instant otherInstant)*メソッドの宣言です。
public boolean isAfter(Instant otherInstant)
パラメーター
*otherInstant* -比較する他のインスタント、nullではない。
戻り値
このインスタントが指定されたインスタントの後にある場合はtrue。
例外
*NullPointerException* -otherInstantがnullの場合。
例
次の例は、java.time.Instant.isAfter(Instant otherInstant)メソッドの使用方法を示しています。
package com.finddevguides;
import java.time.Instant;
public class InstantDemo {
public static void main(String[] args) {
Instant instant = Instant.parse("2017-02-03T10:37:30.00Z");
System.out.println("Instant #1: " + instant);
Instant instant1 = Instant.parse("2017-03-03T10:37:30.00Z");
System.out.println("Instant #2: " + instant1);
boolean result = instant.isAfter(instant1);
System.out.println(result ? "Instant #1 is after Instant #2."
:"Instant #1 is not after as Instant #2.");
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
Instant #1: 2017-02-03T10:37:30Z
Instant #2: 2017-03-03T10:37:30Z
Instant #1 is not after as Instant #2.