MonthDay.range() 方法在 Java 中
使用 Java 中 MonthDay 類的 range() 方法可以獲取 ChronoField 的值範圍。該方法需要一個引數,即要求其值範圍的 ChronoField,並且它會返回值範圍。
演示該方法的一個程式如下:
示例
import java.time.*;
import java.time.temporal.ChronoField;
import java.time.temporal.ValueRange;
public class Main {
public static void main(String[] args) {
MonthDay md = MonthDay.parse("--02-21");
System.out.println("The MonthDay is: " + md);
ValueRange range = md.range(ChronoField.DAY_OF_MONTH);
System.out.println("The range of DAY_OF_MONTH is: " + range);
}
}輸出
The MonthDay is: --02-21 The range of DAY_OF_MONTH is: 1 - 28/29
現在讓我們理解一下上面的程式。
首先顯示 MonthDay。然後使用 range() 方法獲取特定 ChronoField 的值範圍並顯示。演示此方法的程式碼片段如下:
MonthDay md = MonthDay.parse("--02-21");
System.out.println("The MonthDay is: " + md);
ValueRange range = md.range(ChronoField.DAY_OF_MONTH);
System.out.println("The range of DAY_OF_MONTH is: " + range);
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP