Java 中的 LocalDate query() 方法
LocalDate 物件可以使用 Java 中 LocalDate 類的 query 方法根據需要進行查詢。此方法需要一個引數,即要呼叫的查詢,它返回查詢的結果。
演示此方法的程式如下 −
示例
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 物件。然後,使用 query 方法查詢 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);
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP