当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。