java.time.LocalDateTime.isSupported() Method Example



Description

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

Declaration

Following is the declaration for java.time.LocalDateTime.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 date, false if not.

Example

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

package com.tutorialspoint;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

public class LocalDateTimeDemo {
   public static void main(String[] args) {
 
      LocalDateTime date = LocalDateTime.parse("2020-02-03T12:30:30");
      System.out.println(date.isSupported(ChronoUnit.DAYS));  
   }
}

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

true
Advertisements