Wednesday, July 3, 2024
HomeLanguagesJavaTimeZone inDaylightTime() method in Java with Examples

TimeZone inDaylightTime() method in Java with Examples

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

Syntax:

public abstract 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 TimeZone
        TimeZone offtime_zone
            = TimeZone.getTimeZone("Europe/Rome");
  
        // Creating date object
        Date dt = new Date();
  
        // Verifying daylight
        boolean bool_daylight
            = offtime_zone.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? true

Example 2:




// Java code to demonstrate
// inDaylightTime() method
  
import java.util.*;
  
public class SimpleTimeZone_Demo {
    public static void main(String[] args)
    {
        // Creating a TimeZone
        TimeZone offtime_zone
            = TimeZone.getTimeZone("Pacific/Pago_Pago");
  
        // Creating date object
        Date dt = new Date();
  
        // Verifying daylight
        boolean bool_daylight
            = offtime_zone.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/7/docs/api/java/util/TimeZone.html#inDaylightTime(java.util.Date)

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments