Close

Java Date Time - ZonedDateTime.isSupported() Examples

Java Date Time Java Java API 


Class:

java.time.ZonedDateTime

java.lang.Objectjava.lang.Objectjava.time.ZonedDateTimejava.time.ZonedDateTimejava.time.temporal.TemporalTemporaljava.time.chrono.ChronoZonedDateTimeChronoZonedDateTimejava.io.SerializableSerializableLogicBig

Methods:

public boolean isSupported(TemporalField field)

This method checks if the provided TemporalField is supported by this instance.


public boolean isSupported(TemporalUnit unit)

This methods check if the provided TemporalUnit is supported by this instance.

Examples


package com.logicbig.example.zoneddatetime;

import java.time.ZonedDateTime;
import java.time.temporal.ChronoField;

public class IsSupportedExample {

public static void main(String... args) {
ZonedDateTime d = ZonedDateTime.now();

for (ChronoField chronoField : ChronoField.values()) {
boolean supported = d.isSupported(chronoField);
System.out.printf("%30s: %s%n", chronoField.name(), supported);
}
}
}

Output

                NANO_OF_SECOND: true
NANO_OF_DAY: true
MICRO_OF_SECOND: true
MICRO_OF_DAY: true
MILLI_OF_SECOND: true
MILLI_OF_DAY: true
SECOND_OF_MINUTE: true
SECOND_OF_DAY: true
MINUTE_OF_HOUR: true
MINUTE_OF_DAY: true
HOUR_OF_AMPM: true
CLOCK_HOUR_OF_AMPM: true
HOUR_OF_DAY: true
CLOCK_HOUR_OF_DAY: true
AMPM_OF_DAY: true
DAY_OF_WEEK: true
ALIGNED_DAY_OF_WEEK_IN_MONTH: true
ALIGNED_DAY_OF_WEEK_IN_YEAR: true
DAY_OF_MONTH: true
DAY_OF_YEAR: true
EPOCH_DAY: true
ALIGNED_WEEK_OF_MONTH: true
ALIGNED_WEEK_OF_YEAR: true
MONTH_OF_YEAR: true
PROLEPTIC_MONTH: true
YEAR_OF_ERA: true
YEAR: true
ERA: true
INSTANT_SECONDS: true
OFFSET_SECONDS: true




package com.logicbig.example.zoneddatetime;

import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;

public class IsSupportedExample2 {

public static void main(String... args) {
ZonedDateTime d = ZonedDateTime.now();

for (ChronoUnit chronoUnit : ChronoUnit.values()) {
boolean supported = d.isSupported(chronoUnit);
System.out.printf("%10s: %s%n", chronoUnit.name(), supported);
}
}
}

Output

     NANOS: true
MICROS: true
MILLIS: true
SECONDS: true
MINUTES: true
HOURS: true
HALF_DAYS: true
DAYS: true
WEEKS: true
MONTHS: true
YEARS: true
DECADES: true
CENTURIES: true
MILLENNIA: true
ERAS: true
FOREVER: false




See Also