ZonedDateTime isSupported() method in Java with Examples
Last Updated :
18 Dec, 2018
In ZonedDateTime class, there are two types of isSupported() method depending upon the parameters passed to it.
isSupported(TemporalField field)
isSupported() method of a
ZonedDateTime class used to check if the specified field is supported by ZonedDateTime class or not means using this method we can check if this ZonedDateTime can be queried for the specified field.
The supported fields of ChronoField are:
- NANO_OF_SECOND
- MICRO_OF_SECOND
- MILLI_OF_SECOND
- INSTANT_SECONDS
- SECOND_OF_MINUTE
- NANO_OF_DAY
- MICRO_OF_DAY
- MILLI_OF_DAY
- SECOND_OF_DAY
- MINUTE_OF_HOUR
- MINUTE_OF_DAY
- HOUR_OF_AMPM
- CLOCK_HOUR_OF_AMPM
- HOUR_OF_DAY
- CLOCK_HOUR_OF_DAY
- AMPM_OF_DAY
- DAY_OF_WEEK
- ALIGNED_DAY_OF_WEEK_IN_MONTH
- ALIGNED_DAY_OF_WEEK_IN_YEAR
- DAY_OF_MONTH
- DAY_OF_YEAR
- EPOCH_DAY
- ALIGNED_WEEK_OF_MONTH
- ALIGNED_WEEK_OF_YEAR
- MONTH_OF_YEAR
- PROLEPTIC_MONTH
- YEAR_OF_ERA
- YEAR
- ERA
- INSTANT_SECONDS
- OFFSET_SECONDS
All other ChronoField instances will return false.
Syntax:
public boolean isSupported(TemporalField field)
Parameters: This method accepts one single parameter
field which is the field to check.
Return value: This method returns
boolean value true if the field is supported on this date-time, false if not.
Below programs illustrate the isSupported() method:
Program 1:
Java
// Java program to demonstrate
// ZonedDateTime.isSupported() method
import java.time.*;
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
// create a ZonedDateTime object
ZonedDateTime zdt
= ZonedDateTime
.parse(
"2018-12-06T19:21:12.123+05:30[Asia/Calcutta]");
// check ALIGNED_WEEK_OF_YEAR
// is supported in ZonedDateTime
boolean value
= zdt.isSupported(
ChronoField.ALIGNED_WEEK_OF_YEAR);
// print result
System.out.println("ALIGNED_WEEK_OF_YEAR "
+ "Field is supported: "
+ value);
}
}
Output:
ALIGNED_WEEK_OF_YEAR Field is supported: true
isSupported(TemporalUnit unit)
isSupported() method of a
ZonedDateTime class used to Check if the specified unit is supported by ZonedDateTime class or not means using this method we can check if this ZonedDateTime can be queried for the specified unit.
The supported fields of ChronoUnit are:
- NANOS
- MICROS
- MILLIS
- SECONDS
- MINUTES
- HOURS
- HALF_DAYS
- DAYS
- WEEKS
- MONTHS
- YEARS
- DECADES
- CENTURIES
- MILLENNIA
- ERAS
All other ChronoUnit instances will return false.
Syntax:
public boolean isSupported(TemporalUnit unit)
Parameters: This method accepts one single parameter
unit which is the unit to check.
Return value: This method returns
boolean value true if the field is supported on this date-time, false if not.
Below programs illustrate the isSupported() method:
Program 1:
Java
// Java program to demonstrate
// ZonedDateTime.isSupported() method
import java.time.*;
import java.time.temporal.ChronoUnit;
public class GFG {
public static void main(String[] args)
{
// create a ZonedDateTime object
ZonedDateTime lt
= ZonedDateTime
.parse(
"2018-12-06T19:21:12.123+05:30[Asia/Calcutta]");
// check MILLENNIA ChronoUnit supported
// in ZonedDateTime
boolean value
= lt.isSupported(ChronoUnit.MILLENNIA);
// print result
System.out.println("ChronoUnit MILLENNIA "
+ "is supported: "
+ value);
}
}
Output:
ChronoUnit MILLENNIA is supported: true
Reference:
Similar Reads
ZonedDateTime getMinute() method in Java with Examples The getMinute() method of a ZonedDateTime class is used to get the minute-of-hour field from this ZonedDateTime. This method returns the integer value for the minute from 0 to 59. Syntax: public int getMinute() Parameters: This method does not take any parameters. Return value: This method returns a
1 min read
ZonedDateTime of() Method in Java with Examples In ZonedDateTime class, there are three types of() method depending upon the parameters passed to it. of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneId zone) of() method of a ZonedDateTime class used to get an instance of ZonedDateTime from a year, mo
3 min read
ZonedDateTime now() Method in Java with Examples In ZonedDateTime class, there are three types of now() method depending upon the parameters passed to it. now() now() method of a ZonedDateTime class used to obtain the current date-time from the system clock in the default time-zone.This method will return ZonedDateTime based on system clock with d
3 min read
ZonedDateTime get() method in Java with Examples The get() method of ZonedDateTime class in Java is used to get the value of the specified field passed as input from this ZonedDateTime as an integer.This method queries this ZonedDateTime for the value of the field and the returned value will always be within the valid range of values for the field
2 min read
ZonedDateTime form() method in Java with Examples The from() method of ZonedDateTime class in Java is used to get instance of ZonedDateTime from TemporalAccessor object passed as parameter. A TemporalAccessor represents an arbitrary set of date and time information and this method helps to get an instant of ZonedDateTime based on the specified Temp
2 min read