SimpleTimeZone inDaylightTime() method in Java with Examples

The inDaylightTime(Date) method of SimpleTimeZone class in Java is used to check and verify whether the given date is in daylight saving time.

Syntax:

public boolean inDaylightTime(Date date)

Parameters: The method takes one parameter date of Date type which is the given date to be verified.



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.

Below programs illustrate the use of inDaylightTime() Method in Java:
Example 1:

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
        SimpleTimeZone simtimeobj
            = new SimpleTimeZone(540, "GMT");
  
        // Creating date object
        Date dt = new Date();
  
        // Verifying daylight
        boolean bool_daylight
            = simtimeobj.inDaylightTime(dt);
  
        // Checking the value of day light
        System.out.println("Is it in day"
                           + " light saving time? "
                           + bool_daylight);
    }
}

chevron_right


Output:

Is it in day light saving time? 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
        SimpleTimeZone simtimeobj
            = new SimpleTimeZone(400, "AUS");
  
        // Creating a Calendar object
        Calendar c1 = Calendar.getInstance();
  
        // Set Month
        // MONTH starts with 0 i.e.(0 - Jan)
        c1.set(Calendar.MONTH, 00);
  
        // Set Date
        c1.set(Calendar.DATE, 30);
  
        // Set Year
        c1.set(Calendar.YEAR, 2019);
  
        // Creating a date object
        // with specified time.
        Date dt = c1.getTime();
  
        // Verifying daylight
        boolean bool_daylight
            = simtimeobj.inDaylightTime(dt);
  
        // Checking the value of day light
        System.out.println("Is it in day"
                           + " light saving time? "
                           + bool_daylight);
    }
}

chevron_right


Output:

Is it in day light saving time? false

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/SimpleTimeZone.html#inDaylightTime-java.util.Date-



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.