TimeZone observesDaylightTime() method in Java with Examples
Last Updated :
29 Apr, 2019
The observesDaylightTime() method of TimeZone class in Java is used to check and verify whether the given date is in daylight saving time or if any transition from Standard Time to Daylight Saving Time will occur at any future time.
Syntax:
public boolean observesDaylightTime()
Parameters: The method does not take any parameters.
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. By default, the method returns True.
Below programs illustrate the use of observesDaylightTime() Method in Java:
Example 1:
import java.util.*;
public class TimeZone_Demo {
public static void main(String[] args)
{
TimeZone timeobj
= TimeZone
.getTimeZone( "Pacific/Pago_Pago" );
System.out.println(timeobj);
boolean bool_daylight
= timeobj.observesDaylightTime();
System.out.println( "The result is: "
+ bool_daylight);
}
}
|
Output:
sun.util.calendar.ZoneInfo[id=”Pacific/Pago_Pago”, offset=-39600000, dstSavings=0,
useDaylight=false, transitions=3, lastRule=null]
The result is: false
Example 2:
import java.util.*;
public class SimpleTimeZone_Demo {
public static void main(String[] args)
{
TimeZone timeobj
= TimeZone
.getTimeZone( "Indian/Chagos" );
System.out.println(timeobj);
boolean bool_daylight
= timeobj.observesDaylightTime();
System.out.println( "The result is: "
+ bool_daylight);
}
}
|
Output:
sun.util.calendar.ZoneInfo[id=”Indian/Chagos”, offset=21600000, dstSavings=0, useDaylight=false, transitions=4, lastRule=null]
The result is: false
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#observesDaylightTime()
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...