Java中的MonthDay range()方法
可以使用range()Java中MonthDay类中的方法来获取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);热门推荐
10 男孩中考蛋糕祝福语简短
11 医师考试祝福语毕业简短
12 虎年幽默搞笑简短祝福语
13 送给新娘祝福语简短高级
14 简短深沉的生日祝福语
15 六一祝福语简短网名
16 开业贺卡祝福语简短高级
17 送同学的简短祝福语
18 传统正版婚礼祝福语简短