ChronoField枚举的isTimeBased()方法用于检查此ChronoField是否表示时间的组成部分.ChronoField常数从纳秒到am-pm-of-day是基于时间的。
用法:
public boolean isTimeBased()
参数:此方法不接受任何内容。
返回值:如果它是时间的一部分,则此方法返回true。
以下示例程序旨在说明ChronoField.isTimeBased()方法:
程序1:
// Java program to demonstrate
// ChronoField.isTimeBased() 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 isTimeBased()
boolean isTimeBasedAttribute
= chronoField.isTimeBased();
// print
System.out.println(
"HOUR_OF_DAY"
+ " is Time based attribute:"
+ isTimeBasedAttribute);
}
}
输出:
HOUR_OF_DAY is Time based attribute:true
程序2:
// Java program to demonstrate
// ChronoField.isTimeBased() 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 isTimeBased()
boolean isTimeBasedAttribute
= chronoField.isTimeBased();
// print
System.out.println("YEAR_OF_ERA"
+ " is Time based attribute:"
+ isTimeBasedAttribute);
}
}
输出:
YEAR_OF_ERA is Time based attribute:false
参考:https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoField.html#isTimeBased()
相关用法
- Java ChronoUnit isTimeBased()用法及代码示例
- Java ChronoField checkValidIntValue()用法及代码示例
- Java ChronoField valueOf()用法及代码示例
- Java ChronoField range()用法及代码示例
- Java ChronoField range()用法及代码示例
- Java ChronoField values()用法及代码示例
- Java ChronoField checkValidValue()用法及代码示例
- Java ChronoField isDateBased()用法及代码示例
- Java Java.util.Collections.rotate()用法及代码示例
- Java Java lang.Long.builtcount()用法及代码示例
- Java Java lang.Long.reverse()用法及代码示例
- Java Java.util.Collections.disjoint()用法及代码示例
- Java Java lang.Long.byteValue()用法及代码示例
- Java Java lang.Long.highestOneBit()用法及代码示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 ChronoField isTimeBased() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。