Java TemporalQuery create for precision and LocalDate

Description

Java TemporalQuery create for precision and LocalDate

import java.time.LocalDate;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;

public class Main {
  public static void main(String[] args) {
    // Get references of the precision and local date queries
    TemporalQuery<TemporalUnit> precisionQuery = TemporalQueries.precision();
    TemporalQuery<LocalDate> localDateQuery = TemporalQueries.localDate();

    // Query a LocalDate
    LocalDate ld = LocalDate.now();
    TemporalUnit precision = ld.query(precisionQuery);
    LocalDate queryDate = ld.query(localDateQuery);
    System.out.println("Precision of LocalDate: " + precision);
    System.out.println("LocalDate of LocalDate: " + queryDate);

  }/*from  w w w . j  a va2 s  .c  o  m*/
}



PreviousNext

Related