Java中的LocalDateTime query()方法
可以根据需要使用Java中LocalDateTime类中的查询方法查询LocalDateTime对象。此方法需要单个参数,即要调用的查询,并且它返回查询的结果。
演示此的程序如下所示-
示例
import java.time.*;
import java.time.temporal.*;
public class Demo {
public static void main(String[] args) {
LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");
System.out.println("The LocalDateTime is: " + ldt);
String precision = ldt.query(TemporalQueries.precision()).toString();
System.out.println("The Precision for the LocalDateTime is: "+ precision);
}
}输出结果
The LocalDateTime is: 2019-02-18T23:15:30 The Precision for the LocalDateTime is: Nanos
现在让我们了解上面的程序。
首先显示LocalDateTime对象。然后使用该query()方法查询LocalDateTime对象,并显示查询结果。演示这的代码片段如下-
LocalDateTime ldt = LocalDateTime.parse("2019-02-18T23:15:30");
System.out.println("The LocalDateTime is: " + ldt);
String precision = ldt.query(TemporalQueries.precision()).toString();
System.out.println("The Precision for the LocalDateTime is: "+ precision);热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短