当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java ChronoUnit isDurationEstimated()用法及代码示例


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

用法:

public boolean isDurationEstimated()

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


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

以下示例程序旨在说明ChronoUnit.isDurationEstimated()方法:
程序1:

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

程序2:

// 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://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoUnit.html#isDurationEstimated()



相关用法


注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 ChronoUnit isDurationEstimated() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。