- 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 getTimeZone() Method
Description
The Java TimeZone getTimeZone(String ID) method is used to get the TimeZone for the given ID.
Declaration
Following is the declaration for java.util.TimeZone.getTimeZone() method.
public static TimeZone getTimeZone(String ID)
Parameters
ID − This is the ID for a TimeZone.
Return Value
The method call returns the specified TimeZone, or the GMT zone if the given ID cannot be understood.
Exception
NA
Getting TimeZone of GMT-8 Example
The following example shows the usage of Java TimeZone getTimeZone() method to get the Time zone based on given Id. We've created a TimeZone using getDefault() method. Using getTimeZone() we're printing the TimeZone object of GMT - 8.
package com.tutorialspoint; import java.util.TimeZone; public class TimeZoneDemo { public static void main( String args[] ) { // create time zone object TimeZone timezone = TimeZone.getDefault(); // checking time zone value System.out.println("Time zone: " + timezone.getTimeZone("GMT-8:00")); } }
Output
Let us compile and run the above program, this will produce the following result.
Time zone: sun.util.calendar.ZoneInfo[id="GMT-08:00",offset=-28800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
Getting TimeZone of IST Example
The following example shows the usage of Java TimeZone getTimeZone() method to get the Time zone based on given Id. We've created a TimeZone using getDefault() method. Using getTimeZone() we're printing the TimeZone object of IST.
package com.tutorialspoint; import java.util.TimeZone; public class TimeZoneDemo { public static void main( String args[] ) { // create time zone object TimeZone timezone = TimeZone.getDefault(); // checking time zone value System.out.println("Time zone: " + timezone.getTimeZone("IST")); } }
Output
Let us compile and run the above program, this will produce the following result.
Time zone:sun.util.calendar.ZoneInfo[id="IST",offset=19800000,dstSavings=0,useDaylight=false,transitions=7,lastRule=null]
Getting TimeZone of BST Example
The following example shows the usage of Java TimeZone getTimeZone() method to get the Time zone based on given Id. We've created a TimeZone using getDefault() method. Using getTimeZone() we're printing the TimeZone object of BST.
package com.tutorialspoint; import java.util.TimeZone; public class TimeZoneDemo { public static void main( String args[] ) { // create time zone object TimeZone timezone = TimeZone.getDefault(); // checking time zone value System.out.println("Time zone: " + timezone.getTimeZone("BST")); } }
Output
Let us compile and run the above program, this will produce the following result.
Time zone: sun.util.calendar.ZoneInfo[id="BST",offset=21600000,dstSavings=0,useDaylight=false,transitions=8,lastRule=null]
To Continue Learning Please Login
Login with Google