Java中的LocalDate query()方法
可以根据需要使用Java中LocalDate类中的查询方法查询LocalDate对象。此方法需要单个参数,即要调用的查询,并且它返回查询的结果。
演示此的程序如下所示-
示例
import java.time.*;
import java.time.temporal.*;
public class Demo {
public static void main(String[] args) {
LocalDate ld = LocalDate.parse("2019-02-14");
System.out.println("The LocalDate is: " + ld);
String precision = ld.query(TemporalQueries.precision()).toString();
System.out.println("The Precision for the LocalDate is: "+ precision);
}
}输出结果
The LocalDate is: 2019-02-14 The Precision for the LocalDate is: Days
现在让我们了解上面的程序。
首先显示LocalDate对象。然后使用查询方法查询LocalDate对象,并显示查询结果。演示这的代码片段如下-
LocalDate ld = LocalDate.parse("2019-02-14");
System.out.println("The LocalDate is: " + ld);
String precision = ld.query(TemporalQueries.precision()).toString();
System.out.println("The Precision for the LocalDate is: "+ precision);