當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。