ChronoUnit枚举的isDateBased()方法用于检查此ChronoUnit是否为日期单位。从天到时代的所有ChronoUnit都是基于日期的。
用法:
public boolean isDateBased()
参数:此方法不接受任何内容。
返回值:如果以日期为单位,则此方法返回true;如果以时间为单位,则返回false。
以下示例程序旨在说明ChronoUnit.isDateBased()方法:
程序1:
// 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
程序2:
// 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://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoUnit.html#isDateBased()
相关用法
- Java ChronoField isDateBased()用法及代码示例
- Java ChronoUnit valueOf()用法及代码示例
- Java ChronoUnit values()用法及代码示例
- Java ChronoUnit isDurationEstimated()用法及代码示例
- Java ChronoUnit getDuration()用法及代码示例
- Java ChronoUnit isTimeBased()用法及代码示例
- Java Java lang.Long.byteValue()用法及代码示例
- Java Java.util.Collections.disjoint()用法及代码示例
- Java Java.util.Collections.rotate()用法及代码示例
- Java Java lang.Long.reverse()用法及代码示例
- Java Java lang.Long.builtcount()用法及代码示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代码示例
- Java Java lang.Long.lowestOneBit()用法及代码示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 ChronoUnit isDateBased() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。