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


Java TimeZone observesDaylightTime()用法及代码示例


Java中的TimeZone类的observesDaylightTime()方法用于检查和验证给定日期是否在夏时制中,或者将来任何时候都将发生从标准时间到夏时制的任何转换。

用法:

public boolean observesDaylightTime()

参数:该方法不带任何参数。


返回值:如果传递的日期相对于夏时制无效,则该方法返回布尔值True,否则返回布尔值False。默认情况下,该方法返回True。

以下程序说明了Java中observesDaylightTime()方法的用法:
示例1:

// Java code to demonstrate 
// observesDaylightTime() method 
  
import java.util.*; 
  
public class TimeZone_Demo { 
    public static void main(String[] args) 
    { 
        // Creating a time zone object 
        TimeZone timeobj 
            = TimeZone 
                  .getTimeZone("Pacific/Pago_Pago"); 
  
        // Displaying the time zone 
  
        System.out.println(timeobj); 
        // Verifying daylight 
        boolean bool_daylight 
            = timeobj.observesDaylightTime(); 
  
        // Checking the value of day light 
        System.out.println("The result is: "
                           + bool_daylight); 
    } 
}
输出:

sun.util.calendar.ZoneInfo[id=”Pacific/Pago_Pago”, offset=-39600000, dstSavings=0,
useDaylight=false, transitions=3, lastRule=null]
The result is: false

示例2:

// Java code to demonstrate 
// inDaylightTime() method 
  
import java.util.*; 
  
public class SimpleTimeZone_Demo { 
    public static void main(String[] args) 
    { 
        // Creating a time zone object 
        TimeZone timeobj 
            = TimeZone 
                  .getTimeZone("Indian/Chagos"); 
  
        // Displaying the time zone 
  
        System.out.println(timeobj); 
        // Verifying daylight 
        boolean bool_daylight 
            = timeobj.observesDaylightTime(); 
  
        // Checking the value of day light 
        System.out.println("The result is: "
                           + bool_daylight); 
    } 
}
输出:

sun.util.calendar.ZoneInfo[id=”Indian/Chagos”, offset=21600000, dstSavings=0, useDaylight=false, transitions=4, lastRule=null]
The result is: false

参考:https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#observesDaylightTime()



相关用法


注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 TimeZone observesDaylightTime() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。