Java Date Time Java Java API
Class:
java.time.LocalDateTime
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.
If this method returns true for the specified unit, then corresponding value can be added to, or subtracted from, this date. If false, then calling the plus and minus methods will throw an exception.
Examples
package com.logicbig.example.localdatetime;
import java.time.LocalDateTime; import java.time.temporal.ChronoField;
public class IsSupportedExample {
public static void main (String... args) { LocalDateTime d = LocalDateTime.now(); 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 false
package com.logicbig.example.localdatetime;
import java.time.LocalDateTime; import java.time.temporal.ChronoUnit;
public class IsSupportedExample2 {
public static void main (String... args) { LocalDateTime d = LocalDateTime.now(); 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.MICROS); System.out.println(b3); } }
Outputtrue true true
|