Java Data Type How to - Query if the Temporal support milli seconds








Question

We would like to know how to query if the Temporal support milli seconds.

Answer

import java.time.Clock;
import java.time.Instant;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQuery;
//from   w  w  w  . j a va 2  s. c o  m
public class Main {

  public static void main(String[] args) {
    Clock defaultClock = Clock.systemDefaultZone();

    Instant instant = Instant.now(defaultClock);

    TemporalQuery query = (TemporalAccessor x) -> x
        .isSupported(ChronoField.MILLI_OF_DAY);

    System.out.println(instant.query(query));
  }
}

The code above generates the following result.