java.time.Instant.isSupported() Method Example



Description

The java.time.Instant.isSupported(TemporalUnit unit) method checks if the specified unit is supported.

Declaration

Following is the declaration for java.time.Instant.isSupported(TemporalUnit unit) method.

public boolean isSupported(TemporalUnit unit)

Parameters

unit − the unit to check, null returns false.

Return Value

true if the unit is supported on this instant, false if not.

Example

The following example shows the usage of java.time.Instant.isSupported(TemporalUnit unit) method.

package com.tutorialspoint;

import java.time.Instant;
import java.time.temporal.ChronoUnit;

public class InstantDemo {
   public static void main(String[] args) {

      Instant instant = Instant.parse("2017-02-03T10:37:30.00Z");
      boolean result = instant.isSupported(ChronoUnit.SECONDS);
      System.out.println(result);  
   }
}

Let us compile and run the above program, this will produce the following result −

true
Advertisements