TimeZone observesDaylightTime() method in Java with Examples

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


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()



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.