TimeZone setDefault() Method in Java with Examples
Last Updated :
29 Apr, 2019
The setDefault(TimeZone zone) method of TimeZone class in Java is used to set the TimeZone of the object that is returned by the getDefault() method of the TimeZone class.
Syntax:
public static void
setDefault(TimeZone zone)
Parameters: The method takes one parameter zone of TimeZone type which refers to the new default timezone.
Return Value: The method does not return any value.
Below program illustrates the working of setDefault() Method of TimeZone.
Example 1:
import java.util.*;
public class TimeZoneDemo {
public static void main(String args[])
{
TimeZone time_zone_default
= TimeZone.getTimeZone( "Europe/Rome" );
time_zone_default.setDefault(time_zone_default);
System.out.println( "Default TimeZone: "
+ time_zone_default);
}
}
|
Output:
Default TimeZone: sun.util.calendar.ZoneInfo[id="Europe/Rome", offset=3600000,
dstSavings=3600000, useDaylight=true, transitions=169, lastRule=java.util.SimpleTimeZone
[id=Europe/Rome, offset=3600000, dstSavings=3600000, useDaylight=true, startYear=0,
startMode=2, startMonth=2, startDay=-1, startDayOfWeek=1, startTime=3600000, startTimeMode=2,
endMode=2, endMonth=9, endDay=-1, endDayOfWeek=1, endTime=3600000, endTimeMode=2]]
Example 2:
import java.util.*;
public class TimeZoneDemo {
public static void main(String args[])
{
TimeZone time_zone_default
= TimeZone.getTimeZone( "Pacific/Pago_Pago" );
time_zone_default.setDefault(time_zone_default);
System.out.println( "Default TimeZone: "
+ time_zone_default);
}
}
|
Output:
Default TimeZone: sun.util.calendar.ZoneInfo[id="Pacific/Pago_Pago",
offset=-39600000, dstSavings=0, useDaylight=false, transitions=3, lastRule=null]
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#setDefault(java.util.TimeZone)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...