提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
查询Datetime对象
import java.time.LocalDate; import java.time.LocalTime;/** 来 自 时代Java公众号 - N o w J a v a . c o m**/ 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 LocalDate LocalDate ld = LocalDate.now(); TemporalUnit precision = ld.query(precisionQuery); LocalDate queryDate = ld.query(localDateQuery); System.out.println("Precision of LocalDate: " + precision); /** 来 自 时代Java公众号 - nowjava.com **/ System.out.println("LocalDate of LocalDate: " + queryDate); // Query a LocalTime LocalTime lt = LocalTime.now(); precision = lt.query(precisionQuery); queryDate = lt.query(localDateQuery); System.out.println("Precision of LocalTime: " + precision); System.out.println("LocalDate of LocalTime: " + queryDate); // Query a ZonedDateTime