Esempio di metodo java.time.Instant.isBefore ()

Descrizione

Il java.time.Instant.isBefore(Instant otherInstant) metodo controlla se questo istante è precedente all'istante specificato.

Dichiarazione

Di seguito è riportata la dichiarazione per java.time.Instant.isBefore(Instant otherInstant) metodo.

public boolean isBefore(Instant otherInstant)

Parametri

otherInstant - l'altro istante con cui confrontare, non nullo.

Valore di ritorno

true se questo istante è precedente all'istante specificato.

Eccezioni

NullPointerException - se otherInstant è nullo.

Esempio

L'esempio seguente mostra l'utilizzo del metodo java.time.Instant.isBefore (Instant otherInstant).

package com.tutorialspoint;

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.isBefore(instant1);
      System.out.println(result ? "Instant #1 is before Instant #2."
         :"Instant #1 is not before as Instant #2.");  
   }
}

Compiliamo ed eseguiamo il programma sopra, questo produrrà il seguente risultato:

Instant #1: 2017-02-03T10:37:30Z
Instant #2: 2017-03-03T10:37:30Z
Instant #1 is before Instant #2.