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 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:
Java
// Program to illustrate the isSupported(TemporalUnit) methodimport 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)); }} |
2018-11-03T12:45:30 true
Program 2:
Java
// Program to illustrate the isSupported(TemporalField) methodimport 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)); }} |
2018-11-03T12:45:30 true
