Sunday, February 15, 2026
HomeLanguagesJavaSimpleTimeZone inDaylightTime() method in Java with Examples

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:




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


Output:

Is it in day light saving time? 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
        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);
    }
}


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-

RELATED ARTICLES

Most Popular

Dominic
32505 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6880 POSTS0 COMMENTS
Nicole Veronica
12003 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12097 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6966 POSTS0 COMMENTS
Umr Jansen
6954 POSTS0 COMMENTS