Java Date Time - LocalDateTime query(TemporalQuery query) example








LocalDateTime query(TemporalQuery<R> query) queries this date-time 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.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.TemporalQueries;
//w w w . j a v a 2  s .c  om
public class Main {
  public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 00);
    
    LocalTime t = a.query(TemporalQueries.localTime());
    
    System.out.println(t);
  }
}

The code above generates the following result.