Java中的 ChronoField values() 方法及示例
ChronoField 枚举的values()方法用于包含此枚举类型的常量的数组,按顺序声明它们。
句法:
public static ChronoField[] values()
参数:此方法不接受任何内容。
返回值:此方法返回一个包含此枚举类型的常量的数组,按顺序,它们被声明。
下面的程序说明了 ChronoField.values() 方法:
方案一:
// Java program to demonstrate
// ChronoField.values() method
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
// get chronoField
ChronoField chronoField
= ChronoField.valueOf("HOUR_OF_DAY");
// apply values()
ChronoField[] array
= chronoField.values();
// print
for (int i = 0; i < array.length; i++)
System.out.println(array[i]);
}
}
输出:
NanoOfSecond
NanoOfDay
MicroOfSecond
MicroOfDay
MilliOfSecond
MilliOfDay
SecondOfMinute
SecondOfDay
MinuteOfHour
MinuteOfDay
HourOfAmPm
ClockHourOfAmPm
HourOfDay
ClockHourOfDay
AmPmOfDay
DayOfWeek
AlignedDayOfWeekInMonth
AlignedDayOfWeekInYear
DayOfMonth
DayOfYear
EpochDay
AlignedWeekOfMonth
AlignedWeekOfYear
MonthOfYear
ProlepticMonth
YearOfEra
Year
Era
InstantSeconds
OffsetSeconds
方案二:
// Java program to demonstrate
// ChronoField.values() method
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
// get chronoField
ChronoField chronoField
= ChronoField.valueOf("HOUR_OF_DAY");
// apply values()
ChronoField[] array
= chronoField.values();
// print
System.out.println("ChronoField length:"
+ array.length);
}
}
输出:
ChronoField length:30
参考资料:https: Java()