Java Date Time - DayOfWeek query(TemporalQuery query) example








DayOfWeek query(TemporalQuery<R> query) queries this day-of-week using the specified query.

Syntax

query has the following syntax.

public <R> R query(TemporalQuery<R> query)

Example

The following example shows how to use query.

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
//ww  w  .j  a v  a  2 s  .c  om
public class Main {
  public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, Month.JUNE, 21);
    DayOfWeek dayOfWeek = DayOfWeek.from(localDate);
    
    TemporalQuery<TemporalUnit> localDateQuery = TemporalQueries.precision();
    
    
    System.out.println(dayOfWeek.query(localDateQuery));
  }
}

The code above generates the following result.