使用java.time.chrono.MinguoDate类的range()方法从TemporalField类型的指定字段获取范围。
用法:
public ValueRange range(TemporalField field)
参数:此方法将TemporalField类型的字段作为要获取其范围的参数。
返回值:此方法以ValueRange的形式返回指定字段的范围。
下面的示例说明了range()方法:
范例1:
Java
// Java program to demonstrate
// range() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] argv)
{
try {
// Creating and initializing
// MinguoDate Object
MinguoDate hidate = MinguoDate.now();
// Getting the ValueRange for
// given ChronoField
// by using range() method
ValueRange range
= hidate.range(ChronoField.ERA);
// display the result
System.out.println("Equivalent Range:"
+ range);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown:" + e);
}
}
}
输出:
Equivalent Range:0 - 1
范例2:
Java
// Java program to demonstrate
// range() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.temporal.*;
public class GFG {
public static void main(String[] argv)
{
try {
// Creating and initializing
// MinguoDate Object
MinguoDate hidate = MinguoDate.now();
// Getting the ValueRange for
// given ChronoField
// by using range() method
ValueRange range
= hidate.range(ChronoField.YEAR);
// display the result
System.out.println("Equivalent Range:"
+ range);
}
catch (DateTimeException e) {
System.out.println("passed parameter can"
+ " not form a date");
System.out.println("Exception thrown:" + e);
}
}
}
输出:
Equivalent Range:-1000001910 - 999998088
相关用法
- Java MinguoDate from()用法及代码示例
- Java MinguoDate now()用法及代码示例
- Java MinguoDate of(int, int, int)用法及代码示例
- Java MinguoDate toString()用法及代码示例
- Java MinguoDate equals()用法及代码示例
- Java MinguoDate getLong()用法及代码示例
- Java MinguoDate toEpochDay()用法及代码示例
- Java MinguoDate atTime()用法及代码示例
- Java MinguoDate getEra()用法及代码示例
- Java MinguoDate hashCode()用法及代码示例
- Java MinguoDate lengthOfMonth()用法及代码示例
- Java MinguoDate getChronology()用法及代码示例
- Java MinguoDate now(ZoneId)用法及代码示例
- Java MinguoDate plus(long, TemporalUnit)用法及代码示例
- Java MinguoDate minus(long, TemporalUnit)用法及代码示例
注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 MinguoDate range() method in Java with Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。