SimpleTimeZone inDaylightTime() method in Java with Examples
Last Updated :
27 Mar, 2019
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:
import java.util.*;
public class SimpleTimeZone_Demo {
public static void main(String[] args)
{
SimpleTimeZone simtimeobj
= new SimpleTimeZone( 540 , "GMT" );
Date dt = new Date();
boolean bool_daylight
= simtimeobj.inDaylightTime(dt);
System.out.println( "Is it in day"
+ " light saving time? "
+ bool_daylight);
}
}
|
Output:
Is it in day light saving time? false
Example 2:
import java.util.*;
public class SimpleTimeZone_Demo {
public static void main(String[] args)
{
SimpleTimeZone simtimeobj
= new SimpleTimeZone( 400 , "AUS" );
Calendar c1 = Calendar.getInstance();
c1.set(Calendar.MONTH, 00 );
c1.set(Calendar.DATE, 30 );
c1.set(Calendar.YEAR, 2019 );
Date dt = c1.getTime();
boolean bool_daylight
= simtimeobj.inDaylightTime(dt);
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-
Share your thoughts in the comments
Please Login to comment...