Java ZonedDateTime query for precision and LocalDate

Description

Java ZonedDateTime query for precision and LocalDate

import java.time.LocalDate;
import java.time.ZonedDateTime;
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 ZonedDateTime
    ZonedDateTime zdt = ZonedDateTime.now();
    TemporalUnit precision = zdt.query(precisionQuery);
    LocalDate queryDate = zdt.query(localDateQuery);
    System.out.println("Precision of ZonedDateTime: " + precision);
    System.out.println("LocalDate of ZonedDateTime: " + queryDate);
  }//from   w w  w.  j  av a 2 s .com
}



PreviousNext

Related