TimeZone setDefault() Method in Java with Examples
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:
// Java code to illustrate setDefault() method import java.util.*; public class TimeZoneDemo { public static void main(String args[]) { // Creating an object of TimeZone class. TimeZone time_zone_default = TimeZone.getTimeZone( "Europe/Rome" ); time_zone_default.setDefault(time_zone_default); // Displaying the default TimeZone System.out.println( "Default TimeZone: " + time_zone_default); } } |
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:
// Java code to illustrate setDefault() method import java.util.*; public class TimeZoneDemo { public static void main(String args[]) { // Creating an object of TimeZone class. TimeZone time_zone_default = TimeZone.getTimeZone( "Pacific/Pago_Pago" ); time_zone_default.setDefault(time_zone_default); // Displaying the default TimeZone System.out.println( "Default TimeZone: " + time_zone_default); } } |
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)
Recommended Posts:
- Locale setDefault() Method in Java with Examples
- TimeZone inDaylightTime() method in Java with Examples
- TimeZone setRawOffset() Method in Java with Examples
- TimeZone useDaylightTime() method in Java with Examples
- TimeZone setID() Method in Java with Examples
- TimeZone observesDaylightTime() method in Java with Examples
- TimeZone getTimeZone() Method in Java with Examples
- TimeZone getDisplayName() Method in Java with Examples
- TimeZone getDefault() Method in Java with Examples
- TimeZone getAvailableIDs() Method in Java with Examples
- TimeZone clone() Method in Java with Examples
- TimeZone getRawOffset() Method in Java with Examples
- TimeZone getID() Method in Java with Examples
- TimeZone getOffset(int, int, int, int, int, int) Method in Java with Examples
- TimeZone getOffset() Method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.