TimeZone inDaylightTime() method in Java with Examples
Last Updated :
29 Apr, 2019
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:
import java.util.*;
public class SimpleTimeZone_Demo {
public static void main(String[] args)
{
TimeZone offtime_zone
= TimeZone.getTimeZone( "Europe/Rome" );
Date dt = new Date();
boolean bool_daylight
= offtime_zone.inDaylightTime(dt);
System.out.println( "Is it in day"
+ " light saving time? "
+ bool_daylight);
}
}
|
Output:
Is it in day light saving time? true
Example 2:
import java.util.*;
public class SimpleTimeZone_Demo {
public static void main(String[] args)
{
TimeZone offtime_zone
= TimeZone.getTimeZone( "Pacific/Pago_Pago" );
Date dt = new Date();
boolean bool_daylight
= offtime_zone.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/7/docs/api/java/util/TimeZone.html#inDaylightTime(java.util.Date)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...