Thursday, August 28, 2025
HomeLanguagesJavaTimeZone getID() Method in Java with Examples

TimeZone getID() Method in Java with Examples

The getID() method of TimeZone class in Java is used to get official ID of a particular TimeZone.

Syntax:

public String getID()

Parameters: The method does not take any parameters.

Return Value: The method returns the ID of the TimeZone.

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




// Java code to illustrate getID() method
  
import java.util.*;
  
public class TimeZoneDemo {
    public static void main(String args[])
    {
  
        // Creating a TimeZone
        TimeZone offtime_zone 
= TimeZone.getTimeZone("Pacific/Pago_Pago");
  
        // Knowing the DST
        System.out.println("The ID is: " 
+ offtime_zone.getID());
    }
}


Output:

The ID is: Pacific/Pago_Pago

Example 2:




// Java code to illustrate getID() method
  
import java.util.*;
  
public class TimeZoneDemo {
    public static void main(String args[])
    {
  
        // Creating a TimeZone
        TimeZone offtime_zone 
= TimeZone.getTimeZone("Europe/Rome");
  
        // Knowing the DST
        System.out.println("The ID is: "
 + offtime_zone.getID());
    }
}


Output:

The ID is: Europe/Rome

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

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

Most Popular

Dominic
32236 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6609 POSTS0 COMMENTS
Nicole Veronica
11779 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11828 POSTS0 COMMENTS
Shaida Kate Naidoo
6719 POSTS0 COMMENTS
Ted Musemwa
7002 POSTS0 COMMENTS
Thapelo Manthata
6678 POSTS0 COMMENTS
Umr Jansen
6690 POSTS0 COMMENTS