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


Java ChronoField isTimeBased()用法及代碼示例


ChronoField枚舉的isTimeBased()方法用於檢查此ChronoField是否表示時間的組成部分.ChronoField常數從納秒到am-pm-of-day是基於時間的。

用法:

public boolean isTimeBased()

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


返回值:如果它是時間的一部分,則此方法返回true。

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

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

程序2:

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



相關用法


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