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


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。