Java 中的 MonthDay query() 方法
可以使用 Java 中 MonthDay 類的 query 方法按需查詢 MonthDay 物件。此方法需要一個必需的引數,即要呼叫的查詢,並且返回查詢結果。
演示此方法的程式如下 −
示例
import java.time.*;
import java.time.temporal.*;
public class Demo {
public static void main(String[] args) {
MonthDay md = MonthDay.parse("--02-22");
System.out.println("The MonthDay is: " + md);
String chronology = md.query(TemporalQueries.chronology()).toString();
System.out.println("The Chronology for the MonthDay is: "+ chronology);
}
}輸出
The MonthDay is: --02-22 The Chronology for the MonthDay is: ISO
現在讓我們理解一下上面的程式。
首先,顯示 MonthDay 物件。然後使用 query 方法查詢 MonthDay 物件並顯示查詢結果。演示此方法的程式碼段如下 −
MonthDay md = MonthDay.parse("--02-22");
System.out.println("The MonthDay is: " + md);
String chronology = md.query(TemporalQueries.chronology()).toString();
System.out.println("The Chronology for the MonthDay is: "+ chronology);
廣告:
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP