ChronoField枚举的isDateBased()方法用于检查此ChronoField是否表示日期的组成部分。day-of-week到age的ChronoField常量是基于日期的。
用法:
public boolean isDateBased()
参数:此方法不接受任何内容。
返回值:如果它是日期的组成部分,则此方法返回true。
以下示例程序旨在说明ChronoField.isDateBased()方法:
程序1:
// Java program to demonstrate
// ChronoField.isDateBased() 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 isDateBased()
boolean isDateBasedAttribute
= chronoField.isDateBased();
System.out.println(
"HOUR_OF_DAY"
+ " is Date based attribute:"
+ isDateBasedAttribute);
}
}
输出:
HOUR_OF_DAY is Date based attribute:false
程序2:
// Java program to demonstrate
// ChronoField.isDateBased() method
import java.time.temporal.ChronoField;
public class GFG {
public static void main(String[] args)
{
// get chronoField
ChronoField chronoField
= ChronoField.valueOf("YEAR_OF_ERA");
// apply isDateBased()
boolean isDateBasedAttribute
= chronoField.isDateBased();
System.out.println("YEAR_OF_ERA"
+ " is Date based attribute:"
+ isDateBasedAttribute);
}
}
输出:
YEAR_OF_ERA is Date based attribute:true
参考:https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoField.html#isDateBased()