Wednesday, November 20, 2024
Google search engine
HomeLanguagesJavaTimeZone observesDaylightTime() method in Java with Examples

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:




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

RELATED ARTICLES

Most Popular

Recent Comments