Java中的 ChronoField isDateBased() 方法及示例
ChronoField 枚举的isDateBased()方法用于检查此 ChronoField 是否代表日期的组件。从星期几到时代的 ChronoField 常量是基于日期的。
句法:
public boolean isDateBased()
参数:此方法不接受任何内容。
返回值:如果它是日期的组成部分,则此方法返回 true。
下面的程序说明了 ChronoField.isDateBased() 方法:
方案一:
// 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();
// print
System.out.println(
"HOUR_OF_DAY"
+ " is Date based attribute:"
+ isDateBasedAttribute);
}
}
输出:
HOUR_OF_DAY is Date based attribute:false
方案二:
// 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();
// print
System.out.println("YEAR_OF_ERA"
+ " is Date based attribute:"
+ isDateBasedAttribute);
}
}
输出:
YEAR_OF_ERA is Date based attribute:true
参考资料:https: Java/time/temporal/ChronoField.html#isDateBased()