Skip to content
Related Articles

Related Articles

TimeZone observesDaylightTime() method in Java with Examples
  • Last Updated : 29 Apr, 2019
GeeksforGeeks - Summer Carnival Banner

The observesDaylightTime() method of TimeZone class in Java is used to check and verify whether the given date is in daylight saving time or if any transition from Standard Time to Daylight Saving Time will occur at any future time.

Syntax:

public boolean observesDaylightTime()

Parameters: The method does not take any parameters.

Return Value: The method returns boolean True if the passed date is ineffective with respect to the daylight saving time else the method return boolean False. By default, the method returns True.

Below programs illustrate the use of observesDaylightTime() Method in Java:
Example 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);
    }
}
Output:

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

Example 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);
    }
}
Output:

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

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

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :