- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
Java TimeZone setDefault() Method
Description
The Java Timezone setDefault(TimeZone zone) method is used to set the TimeZone that is returned by the getDefault method.
Declaration
Following is the declaration for java.util.TimeZone.setDefault() method.
public static void setDefault(TimeZone zone)
Parameters
zone − This is the new default time zone
Return Value
NA
Exception
NA
Setting a Default Zone for Timezone of America Region Example
The following example shows the usage of Java TimeZone setDefault(TimeZone) method to set the TimeZone to be returned by the getDefault() method. We've created a TimeZone using America/Los_Angeles and then set it to default using setDefault() method. Then using getDefault() method, we've verified the result.
package com.tutorialspoint; import java.util.TimeZone; public class TimeZoneDemo { public static void main( String args[] ) { // create time zone object TimeZone tzone = TimeZone.getTimeZone("America/Los_Angeles"); // set time zone to default tzone.setDefault(tzone); // checking default time zone System.out.println("Default time zone:" +tzone.getDefault()); } }
Output
Let us compile and run the above program, this will produce the following result.
Default time zone:sun.util.calendar.ZoneInfo[id="America/Los_Angeles",offset=-28800000,dstSavings=3600000,useDaylight=true,transitions=185,lastRule=java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]
Setting a Default Zone for Timezone of Africa Region Example
The following example shows the usage of Java TimeZone setDefault(TimeZone) method to set the TimeZone to be returned by the getDefault() method. We've created a TimeZone using Africa/Abidjan and then set it to default using setDefault() method. Then using getDefault() method, we've verified the result.
package com.tutorialspoint; import java.util.TimeZone; public class TimeZoneDemo { public static void main( String args[] ) { // create time zone object TimeZone tzone = TimeZone.getTimeZone("Africa/Abidjan"); // set time zone to default tzone.setDefault(tzone); // checking default time zone System.out.println("Default time zone:" +tzone.getDefault()); } }
Output
Let us compile and run the above program, this will produce the following result.
Default time zone:sun.util.calendar.ZoneInfo[id="Africa/Abidjan",offset=0,dstSavings=0,useDaylight=false,transitions=3,lastRule=null]
Setting a Default Zone for Timezone of Poland Region Example
The following example shows the usage of Java TimeZone setDefault(TimeZone) method to set the TimeZone to be returned by the getDefault() method. We've created a TimeZone using Poland and then set it to default using setDefault() method. Then using getDefault() method, we've verified the result.
package com.tutorialspoint; import java.util.TimeZone; public class TimeZoneDemo { public static void main( String args[] ) { // create time zone object TimeZone tzone = TimeZone.getTimeZone("Poland"); // set time zone to default tzone.setDefault(tzone); // checking default time zone System.out.println("Default time zone:" +tzone.getDefault()); } }
Output
Let us compile and run the above program, this will produce the following result.
Default time zone:sun.util.calendar.ZoneInfo[id="Poland",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=165,lastRule=java.util.SimpleTimeZone[id=Poland,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]]
To Continue Learning Please Login
Login with Google