Java LocalDateTime check supported field

Description

Java LocalDateTime check supported field

import java.time.LocalDateTime;
import java.time.temporal.ChronoField;

public class Main {
  public static void main(String[] args) {
    LocalDateTime  now = LocalDateTime.now(); 
    System.out.println(now.isSupported(ChronoField.YEAR)); 
    System.out.println(now.isSupported(ChronoField.HOUR_OF_DAY));

    System.out.println(ChronoField.YEAR.isSupportedBy(now)); 
    System.out.println(ChronoField.HOUR_OF_DAY.isSupportedBy(now));
  }//from   w w  w . ja  v a  2 s. c om
}



PreviousNext

Related