📜  Java中的 ChronoUnit isDurationEstimated() 方法及示例

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

Java中的 ChronoUnit isDurationEstimated() 方法及示例

ChronoUnit 枚举isDurationEstimated()方法用于检查 ChronoUnit 的持续时间是否是估计值。此 ChronoUnit 中的所有时间单位都被认为是准确的,而此 ChronoUnit 中的所有日期单位都被认为是估计的。

句法:

public boolean isDurationEstimated()

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

返回值:如果估计持续时间,则此方法返回true ,如果准确则返回false

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

// Java program to demonstrate
// ChronoUnit.isDurationEstimated() method
  
import java.time.temporal.ChronoUnit;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get ChronoUnit
        ChronoUnit chronoUnit
            = ChronoUnit.valueOf("NANOS");
  
        // apply isDurationEstimated()
        boolean isDurationEstimatedAttribute
            = chronoUnit.isDurationEstimated();
  
        // print
        System.out.println(
            "NANOS"
            + " is Duration Estimated attribute:"
            + isDurationEstimatedAttribute);
    }
}
输出:
NANOS is Duration Estimated attribute:false

方案二:

// Java program to demonstrate
// ChronoUnit.isDurationEstimated() method
  
import java.time.temporal.ChronoUnit;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get ChronoUnit
        ChronoUnit chronoUnit
            = ChronoUnit.valueOf("DAYS");
  
        // apply isDurationEstimated()
        boolean isDurationEstimatedAttribute
            = chronoUnit.isDurationEstimated();
  
        // print
        System.out.println(
            "DAYS"
            + " is Duration Estimated attribute:"
            + isDurationEstimatedAttribute);
    }
}
输出:
DAYS is Duration Estimated attribute:true

参考资料:https: Java/time/temporal/ChronoUnit.html#isDurationEstimated()