📜  Java中的 ChronoField isTimeBased() 方法及示例

📅  最后修改于: 2022-05-13 01:55:32.495000             🧑  作者: Mango

Java中的 ChronoField isTimeBased() 方法及示例

ChronoField 枚举isTimeBased()方法用于检查此 ChronoField 是否代表时间的一个组成部分。从纳秒到一天中下午的 ChronoField 常量是基于时间的。

句法:

public boolean isTimeBased()

参数:此方法不接受任何内容。

返回值:如果它是时间的组成部分,则此方法返回 true。

下面的程序说明了 ChronoField.isTimeBased() 方法:
方案一:

// 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

方案二:

// 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: Java/time/temporal/ChronoField.html#isTimeBased()