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 好听的元旦简短祝福语