Java中的 ChronoUnit isDateBased() 方法及示例
ChronoUnit 枚举的isDateBased()方法用于检查此 ChronoUnit 是否为日期单位。从天到时代的所有 ChronoUnit 都是基于日期的。
句法:
public boolean isDateBased()
参数:此方法不接受任何内容。
返回值:如果是日期单位,则该方法返回true ,如果是时间单位,则返回false 。
下面的程序说明了 ChronoUnit.isDateBased() 方法:
方案一:
// Java program to demonstrate
// ChronoUnit.isDateBased() method
import java.time.temporal.ChronoUnit;
public class GFG {
public static void main(String[] args)
{
// get ChronoUnit
ChronoUnit chronoUnit
= ChronoUnit.valueOf("DECADES");
// apply isDateBased()
boolean isDateBasedAttribute
= chronoUnit.isDateBased();
// print
System.out.println(
"DECADES"
+ " is Date based attribute:"
+ isDateBasedAttribute);
}
}
输出:
DECADES is Date based attribute:true
方案二:
// Java program to demonstrate
// ChronoUnit.isDateBased() method
import java.time.temporal.ChronoUnit;
public class GFG {
public static void main(String[] args)
{
// get ChronoUnit
ChronoUnit chronoUnit
= ChronoUnit.valueOf("MINUTES");
// apply isDateBased()
boolean isDateBasedAttribute
= chronoUnit.isDateBased();
// print
System.out.println(
"MINUTES"
+ " is Date based attribute:"
+ isDateBasedAttribute);
}
}
输出:
MINUTES is Date based attribute:false
参考资料:https: Java/time/temporal/ChronoUnit.html#isDateBased()