Java Instant isSupported() method

7 Jan 2025 | 3 min read

The isSupported() method of Java Instant class is used to check if the specified field or unit is supported.

The isSupported() method consists of 2 parameters.

Syntax

Parameters

field- The field to check, null returns false.

unit- The unit to check, null returns false.

Return

 

Exceptions

True, if the unit is supported on this instant, false if not.

True, if the unit is supported on this instant, false if not.

Java Instant isSupported(TemporalField field) method

Example 1

Output:

The output will be like this.

 false 

Example 2

Output:

The output will be like this.

 true 

Example 3

Output:

The output will be like this.

 false 

Example 4

Output:

The output will be like this:

 true 

Example 5

Output:

The output will be like this.

 2017-05-01T20:57:45.145Z NanoOfSecond > true NanoOfDay > false MicroOfSecond > true MicroOfDay > false MilliOfSecond > true MilliOfDay > false SecondOfMinute > false SecondOfDay > false MinuteOfHour > false MinuteOfDay > false HourOfAmPm > false ClockHourOfAmPm > false HourOfDay > false ClockHourOfDay > false AmPmOfDay > false DayOfWeek > false AlignedDayOfWeekInMonth > false AlignedDayOfWeekInYear > false DayOfMonth > false DayOfYear > false EpochDay > false AlignedWeekOfMonth > false AlignedWeekOfYear > false MonthOfYear > false ProlepticMonth > false YearOfEra > false Year > false Era > false InstantSeconds > true OffsetSeconds > false 

Java Instant isSupported(TemporalUnit unit) method

Example 6

Output:

The output will be like this.

 true 

Example 7

Output:

The output will be like this.

 false 

Example 8

Output:

The output will be like this.

 true 

Example 9

Output:

The output will be like this.

 false 

Example 10

Output:

The output will be like this.

 2017-05-01T20:57:47.276Z Nanos > true Micros > true Millis > true Seconds > true Minutes > true Hours > true HalfDays > true Days > true Weeks > false Months > false Years > false Decades > false Centuries > false Millennia > false Eras > false Forever > false