Javatime-instant-equals

提供:Dev Guides
移動先:案内検索

java.time.Instant.equals()メソッドの例

説明

  • java.time.Instant.equals(Object otherInstant)*メソッドは、このインスタントが指定されたインスタントと等しいかどうかをチェックします。

宣言

以下は* java.time.Instant.equals(Object otherInstant)*メソッドの宣言です。

public boolean equals(Object otherInstant)

パラメーター

*otherInstant* -もう一方の瞬間、nullはfalseを返します。

戻り値

他のインスタントがこのインスタントと等しい場合はtrue

次の例は、java.time.Instant.equals(Object 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.equals(instant1);
      System.out.println(result ? "Instant #1 is same as Instant #2."
         :"Instant #2 is not same as Instant #1.");
   }
}

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

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