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


Java ZoneOffset isSupported(TemporalField)用法及代碼示例


java.time包中ZoneOffset類的isSupported(TemporalField)方法用於檢查ZoneOffset是否支持作為參數傳遞的temporalField。此方法返回一個聲明相同的布爾值。

用法:

public boolean isSupported(TemporalField temporalField)

參數:此方法接受參數TemporalField,如果此ZoneOffset實例支持它,則需要檢查該參數。


返回值:此方法返回一個布爾值,該值指示此ZoneOffset實例是否支持此temporalField。

以下示例說明了ZoneOffset.isSupported()方法:

示例1:

// Java code to illustrate isSupported() method 
  
import java.time.*; 
import java.time.temporal.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // Get the ZoneOffset instance 
        ZoneOffset zoneOffset 
            = ZoneOffset.of("+05:30"); 
        System.out.println("ZoneOffset: "
                           + zoneOffset); 
  
        // Using isSupported() method 
        System.out.println("Is Second supported: "
                           + zoneOffset.isSupported(ChronoField.OFFSET_SECONDS)); 
    } 
}
輸出:
ZoneOffset: +05:30
Is Second supported: true

示例2:

// Java code to illustrate isSupported() method 
  
import java.time.*; 
import java.time.temporal.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // Get the ZoneOffset instance 
        ZoneOffset zoneOffset 
            = ZoneOffset.ofHours(5); 
        System.out.println("ZoneOffset: "
                           + zoneOffset); 
  
        // Using isSupported() method 
        System.out.println("Is Nano-Of-The-Day supported: "
                           + zoneOffset.isSupported(ChronoField.NANO_OF_DAY)); 
    } 
}
輸出:
ZoneOffset: +05:00
Is Nano-Of-The-Day supported: false

參考: Oracle Doc



相關用法


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