Java Date Time Java Java API
Class:
java.time.OffsetDateTime
Methods:
public boolean isSupported(TemporalField field)
This method checks if the provided TemporalField is supported by this instance.
If this method returns false, then calling the range, get and with methods will throw an exception.
public boolean isSupported(TemporalUnit unit)
This methods check if the provided TemporalUnit is supported by this instance.
Examples
package com.logicbig.example.offsetdatetime;
import java.time.LocalDateTime; import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.time.temporal.ChronoField;
public class IsSupportedExample {
public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2011, 10, 3, 14, 30), ZoneOffset.ofHours(-4));
boolean b = d.isSupported(ChronoField.DAY_OF_MONTH); System.out.println(b);
boolean b2 = d.isSupported(ChronoField.MINUTE_OF_HOUR); System.out.println(b2);
boolean b3 = d.isSupported(ChronoField.OFFSET_SECONDS); System.out.println(b3);
} }
Outputtrue true true
package com.logicbig.example.offsetdatetime;
import java.time.LocalDateTime; import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.time.temporal.ChronoUnit;
public class IsSupportedExample2 {
public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2011, 10, 3, 14, 30), ZoneOffset.ofHours(-4)); boolean b = d.isSupported(ChronoUnit.DAYS); System.out.println(b);
boolean b2 = d.isSupported(ChronoUnit.HALF_DAYS); System.out.println(b2);
boolean b3 = d.isSupported(ChronoUnit.NANOS); System.out.println(b3); } }
Outputtrue true true
|
|