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