ChronoField枚舉的values()方法用於包含此枚舉類型的常量的數組,並按順序聲明它們。
用法:
public static ChronoField[] values()
參數:此方法不接受任何內容。
返回值:此方法返回一個數組,該數組包含此枚舉類型的常量,並按順序聲明它們。
以下示例程序旨在說明ChronoField.values()方法:
程序1:
// 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
程序2:
// 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://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoField.html#values()
相關用法
- Java ChronoField valueOf()用法及代碼示例
- Java ChronoField range()用法及代碼示例
- Java ChronoField range()用法及代碼示例
- Java ChronoField isTimeBased()用法及代碼示例
- Java ChronoField checkValidValue()用法及代碼示例
- Java ChronoField checkValidIntValue()用法及代碼示例
- Java ChronoField isDateBased()用法及代碼示例
- Java ResolverStyle values()用法及代碼示例
- Java AbstractMap values()用法及代碼示例
- Java TimeUnit values()用法及代碼示例
- Java ChronoUnit values()用法及代碼示例
- Java Provider values()用法及代碼示例
- Java DayOfWeek values()用法及代碼示例
- Java TextStyle values()用法及代碼示例
- Java SortedMap values()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 ChronoField values() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。