Thursday, February 5, 2026
HomeLanguagesJavaTimeZone getTimeZone() Method in Java with Examples

TimeZone getTimeZone() Method in Java with Examples

The getTimeZone() method of TimeZone class in Java is used to know the actual TimeZone for any passed TimeZone ID.

Syntax:

public static TimeZone getTimeZone(String the_ID)

Parameters: The method takes one parameter the_ID of string datatype which refers to the ID of which the TimeZone is needed to be known.

Return Value: The method either returns the specified TimeZone for the passed ID or the GMT zone if the specified ID cannot be understood by the program.

Below programs illustrate the working of getTimeZone() Method of TimeZone:
Example 1:




// Java code to illustrate getTimeZone() method
  
import java.util.*;
  
public class TimeZoneDemo {
    public static void main(String args[])
    {
  
        // Creating a TimeZone
        TimeZone the_time_zone
            = TimeZone.getDefault();
  
        // Knowing the TimeZone
        System.out.println("The TimeZone is: "
                           + the_time_zone
                                 .getTimeZone("GMT+5:30"));
    }
}


Output:

The TimeZone is: sun.util.calendar.ZoneInfo[id="GMT+05:30",
offset=19800000, dstSavings=0, useDaylight=false, transitions=0, lastRule=null]

Example 2:




// Java code to illustrate getTimeZone() method
  
import java.util.*;
  
public class TimeZoneDemo {
    public static void main(String args[])
    {
  
        // Creating a TimeZone
        TimeZone the_time_zone
            = TimeZone.getDefault();
  
        // Knowing the TimeZone
        System.out.println("The TimeZone is: "
                           + the_time_zone
                                 .getTimeZone("GMT-3:30"));
    }
}


Output:

The TimeZone is: sun.util.calendar.ZoneInfo[id="GMT-03:30",
offset=-12600000, dstSavings=0, useDaylight=false, transitions=0, lastRule=null]

Reference: https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#getTimeZone()

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32487 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6861 POSTS0 COMMENTS
Nicole Veronica
11983 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12071 POSTS0 COMMENTS
Shaida Kate Naidoo
6994 POSTS0 COMMENTS
Ted Musemwa
7233 POSTS0 COMMENTS
Thapelo Manthata
6945 POSTS0 COMMENTS
Umr Jansen
6926 POSTS0 COMMENTS