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 - 如果otherInstantnull

示例

以下示例顯示了java.time.Instant.isAfter(Instant otherInstant)方法的用法。

package com.zaixian;

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.

上一篇: java.time.Instant類 下一篇: java.time.LocalDate類