Java 中的日本年代范围()方法,示例
原文:https://www . geesforgeks . org/Japanese 年表-范围-java 中的方法-带示例/
Java . time . chrono . Japanese 年表类的 range() 方法用于从 chrono 类型的指定字段中获取的范围。
语法:
public ValueRange range(ChronoField field)
参数:该方法以型计时场的场为参数。
返回值:该方法从指定的类型为 chrono 的字段中返回的范围。
以下是说明范围()方法的示例:
例 1:
// 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
// JapaneseDate Object
JapaneseDate hidate
= JapaneseDate.now();
// getting JapaneseChronology
// used in LocalDate
JapaneseChronology crono
= hidate.getChronology();
// getting the ValueRange for
// given ChronoField
// by using range() method
ValueRange range
= crono.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 : -1 - 2
例 2:
// 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
// JapaneseDate Object
JapaneseDate hidate
= JapaneseDate.now();
// getting JapaneseChronology
// used in LocalDate
JapaneseChronology crono
= hidate.getChronology();
// getting the ValueRange for
// given ChronoField
// by using range() method
ValueRange range
= crono.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 : 1873 - 999999999
版权属于:月萌API www.moonapi.com,转载请注明出处