LocalDateTime `query()` 方法在 Java 中
LocalDateTime 对象可以使用 Java 中 LocalDateTime 类的 query 方法根据需要进行查询。此方法需要一个参数,即要调用的查询,并返回查询的结果。
下面给出了展示此内容的程序 −
示例
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);
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP