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