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


Java ChronoUnit isDateBased()用法及代碼示例


ChronoUnit枚舉的isDateBased()方法用於檢查此ChronoUnit是否為日期單位。從天到時代的所有ChronoUnit都是基於日期的。

用法:

public boolean isDateBased()

參數:此方法不接受任何內容。


返回值:如果以日期為單位,則此方法返回true;如果以時間為單位,則返回false。

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

// Java program to demonstrate 
// ChronoUnit.isDateBased() method 
  
import java.time.temporal.ChronoUnit; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // get ChronoUnit 
        ChronoUnit chronoUnit 
            = ChronoUnit.valueOf("DECADES"); 
  
        // apply isDateBased() 
        boolean isDateBasedAttribute 
            = chronoUnit.isDateBased(); 
  
        // print 
        System.out.println( 
            "DECADES"
            + " is Date based attribute:"
            + isDateBasedAttribute); 
    } 
}
輸出:
DECADES is Date based attribute:true

程序2:

// Java program to demonstrate 
// ChronoUnit.isDateBased() method 
  
import java.time.temporal.ChronoUnit; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // get ChronoUnit 
        ChronoUnit chronoUnit 
            = ChronoUnit.valueOf("MINUTES"); 
  
        // apply isDateBased() 
        boolean isDateBasedAttribute 
            = chronoUnit.isDateBased(); 
  
        // print 
        System.out.println( 
            "MINUTES"
            + " is Date based attribute:"
            + isDateBasedAttribute); 
    } 
}
輸出:
MINUTES is Date based attribute:false

參考:https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoUnit.html#isDateBased()



相關用法


注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 ChronoUnit isDateBased() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。