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