Skip to content
Related Articles

Related Articles

Improve Article

LocalDateTime isSupported() method in Java

  • Last Updated : 10 May, 2019

The isSupported() method of LocalDateTime class in Java checks if the specified unit or field is supported.

Syntax:

public boolean isSupported(TemporalUnit unit)
           or
public boolean isSupported(TemporalField field)

Parameter: This method accepts a parameter field which specifies the field to check, null returns false or it accepts a parameter unit which specifies the the unit to check, null returns false.

Returns: The function returns true if the unit of field is supported on this date, false if not.

Below programs illustrate the LocalDateTime.isSupported() method:



Program 1:




// Program to illustrate the isSupported(TemporalUnit) method
  
import java.util.*;
import java.time.*;
import java.time.temporal.ChronoUnit;
  
public class GfG {
    public static void main(String[] args)
    {
        // Parses the date
        LocalDateTime dt1
            = LocalDateTime.parse("2018-11-03T12:45:30");
  
        // Prints the date
        System.out.println(dt1);
  
        System.out.println(dt1.isSupported(ChronoUnit.DAYS));
    }
}
Output:
2018-11-03T12:45:30
true

Program 2:




// Program to illustrate the isSupported(TemporalField) method
  
import java.util.*;
import java.time.*;
import java.time.temporal.ChronoField;
  
public class GfG {
    public static void main(String[] args)
    {
        // Parses the date
        LocalDateTime dt1
            = LocalDateTime.parse("2018-11-03T12:45:30");
  
        // Prints the date
        System.out.println(dt1);
  
        System.out.println(
            dt1
                .isSupported(ChronoField.DAY_OF_WEEK));
    }
}
Output:
2018-11-03T12:45:30
true

Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDateTime.html#isSupported(java.time.temporal.TemporalField)

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up