LocalDateTime isSupported() method in Java
Last Updated :
06 Jul, 2022
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
import java.util.*;
import java.time.*;
import java.time.temporal.ChronoUnit;
public class GfG {
public static void main(String[] args)
{
LocalDateTime dt1
= LocalDateTime.parse(" 2018 - 11 -03T12: 45 : 30 ");
System.out.println(dt1);
System.out.println(dt1.isSupported(ChronoUnit.DAYS));
}
}
|
Output:
2018-11-03T12:45:30
true
Program 2:
Java
import java.util.*;
import java.time.*;
import java.time.temporal.ChronoField;
public class GfG {
public static void main(String[] args)
{
LocalDateTime dt1
= LocalDateTime.parse(" 2018 - 11 -03T12: 45 : 30 ");
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)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...