當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java ChronoField values()用法及代碼示例


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()



相關用法


注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 ChronoField values() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。