Java LocalDate query for precision and LocalDate

Description

Java LocalDate query for precision and LocalDate

import java.time.LocalDate;
import java.time.LocalTime;
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 LocalTime
    LocalTime lt = LocalTime.now();
    TemporalUnit  precision = lt.query(precisionQuery);
    LocalDate queryDate = lt.query(localDateQuery);
    System.out.println("Precision of LocalTime: " + precision);
    System.out.println("LocalDate of LocalTime: " + queryDate);

  }/*from www.  j a  va2s.  c om*/
}



PreviousNext

Related